class Api::SnipsController < ActionController::API
def show
snip = Snip.includes(:author, :code_blocks).find(params[:id])
if stale?(etag: [snip.cache_key_with_version, snip.code_blocks.maximum(:updated_at)], last_modified: snip.updated_at)
render json: SnipSerializer.new(snip).as_json
end
end
end
ETags are a simple high-impact performance lever: they reduce bandwidth and controller CPU. Use stale? with a stable ETag component list and last_modified so intermediary caches and browsers can do conditional GET.