RailsCasts Pro episodes are now free!
Learn more or hide this
Resources
curl -I http://localhost:3000/ curl -I http://localhost:3000/ -c cookies.txt curl -I http://localhost:3000/ -b cookies.txt curl -I http://localhost:3000/ -b cookies.txt --header 'If-None-Match: "8c90bb6e63dc2868f076c82a939f6654"' curl -I http://localhost:3000/products/1 curl -I http://localhost:3000/products/1 --header 'If-None-Match: "6b110718516575b1a14131d2c7668af5"' curl -I http://localhost:3000/products/1 --header 'If-Modified-Since: Sat, 28 Jan 2012 18:25:53 GMT' rake middleware
def index @products = Product.scoped fresh_when last_modified: @products.maximum(:updated_at) end def show @product = Product.find(params[:id]) expires_in 5.minutes fresh_when @product, public: true # or: # if stale? etag: @product, last_modified: @product.updated_at, public: true # render ... # end end
config.action_controller.perform_caching = true
<%= csrf_meta_tag unless response.cache_control[:public] %>