Just after some advice on how I can cache both a jbuilder view and an activerecord query. The way I'm doing it currently doesn't feel right, as I'm essentially storing two things in the cache. Can I combine this somehow? I need to cache the SQL record so the database doesn't get hit and also the view file to maximise speed.
# Controller
@posts = Rails.cache.fetch ["posts"], :expires_in => 1.hour do
Post.all.limit(10).order("id desc").to_a
end
and
# Jbuilder view
json.cache! ["posts"], :expires_in => 1.hour do |json|
json.array! @posts do |post|
json.id post.id
json.title post.title
end
end