I have the following query in my application
@categories = Category.joins(:posts).select('distinct categories.*').order('label')
This request is loaded into each page view, as the categories are displayed on each page. This seems dirty to me, as the list of categories is often not updated. Is there a great way to cache request only? I tried
Category.cache do @categories = Category.joins(:posts).select('distinct categories.*').order('label') end
but I still see that the request is loaded every time from the database in the development log.
caching activerecord ruby-on-rails-3
Jason yost
source share