I use the following low-level caching for the five latest news in a Rails application:
@recent_news = Rails.cache.fetch("recent_news", :expires_in => 1.hour) do News.order("created_at desc").limit(5) end
Is there a way to cache this request until a new news article is created? I was thinking about manually expiring the cache using an observer, but was not sure if there was a way to do this, for example:
class NewsObserver < ActiveRecord::Observer def after_create
source share