I’ve been developing with Rails for a few years now, but one part I haven’t used is view fragment caching.
I’m using it now, and I’m seeing what I think is undesirable behavior, but I need someone with experience to tell me if it’s supposed to be this way.
I’m caching a collection, and it runs the query to generate the cache key (count, max updated_at) as expected, but then regardless of whether there is a cache hit, it still runs the main query, and if there are includes, it runs those queries, too. If the view fragment is being served from the cache, then those queries are just wasted time. Has it always been like this?
I can work around it by using “<% cache @collection.cache_key do %>” instead of “<% cache @collection do %>”, but it seems like it shouldn’t run the query in the first place.