Module 17 Β· Caching Layers β Lesson 3 of 4 Β· ~9 min
Rails.cache & key-based expiry (Solid Cache)
fresh_when skips the render. Rails.cache skips the WORK.
Conditional GET saves you from re-sending bytes the client already has. It doesn't save you from re-computing the payload when the ETag DOESN'T match, or when the caller is another service (no browser cache, no If-None-Match) that always needs a fresh response body. For that, Rails gives you a general-purpose cache: Rails.cache.fetch(key) { expensive_work }.
fetch checks the cache for key first. A hit returns the cached value β the block never runs. A miss runs the block, stores the result under key, and returns it. One method, both branches.