Fix some cache invalidation bugs