class TrendingSnips
def call
Rails.cache.fetch('snips:trending:v1', expires_in: 5.minutes, race_condition_ttl: 10.seconds) do
Snip.trending.includes(:author).limit(20).to_a
end
end
end
If a hot key expires, you can stampede your DB. race_condition_ttl lets one process recompute while others serve stale content briefly. This is a reliability pattern masquerading as caching.