I’m running into a problem when using fragment caching with active record collections.
Rails 6 uses a combination of collection.cache_key and collection.cache_version to determine whether a fragment cache is fresh or not. However, there is a scenario where the collection might change while collection.cache_key and collection.cache_version stay the same.
It happens when you use a limit on the collection and then destroy one of those records, as long as it’s not the most recent one. This way collection.cache_key will stay the same, because the query does not change. And collection.cache_version will stay the same as well, because the collection count will remain unchanged as does the maximum updated_at timestamp of the most recent record.
I’ve build a sample app for demonstration purposes:
The readme describes a way to reproduce the issue via the website itself, or the Rails console.
Would this be considered a bug or expected behavior? Are there any known work arounds?