Fix deadlock in cache invalidation code