3 ms·
> AFAIK w/Rails ActiveRecord caches queries per-request. Really? That surprises me. Do you have any information about that? My understanding is that there's n
by losvedir 9y ago
> AFAIK w/Rails ActiveRecord caches queries per-request.
Really? That surprises me. Do you have any information about that?
My understanding is that there's no "ambient" caching. Any caching is in the ActiveRecord::Relation objects themselves. So if you had a `users = User.whatever` then `users` might have some logic for deferring to a cache in it, but if you had a separate `users2 = User.whatever` then that wouldn't be subject to the cache. I'm quite sure this is the case for associations: u = User.find(123); u.posts; u.posts, the first statement will query the DB as will the second, but the third won't, since the fact that `u.posts` has been executed will be cached in the `u` object. But if you did `u2 = User.find(123)` that would hit the DB again.
I haven't done any rails 5, so maybe it's new there.
- deedubaya 9y agoI was referring to http://guides.rubyonrails.org/caching_with_rails.html#sql-caching http://guides.rubyonrails.org/caching_with_rails.html#sql-ca... I'm not sure when this was added. v3 or v4?