def file_digest(path) if stat = File.stat(path) cache.fetch("file_digest:#{path}:#{stat.mtime.to_i}") do Digest::SHA256.file(path.to_s).digest end end end 12x
Processing by HomeController#index as HTML Rendered home/index.html.erb within layouts/ application (1.3ms) Completed 200 OK in 224ms (Views: 212.4ms | ActiveRecord: 0.0ms)
And so on for every request for this action. http_cache_forever
Processing by HomeController#index as HTML Rendered home/index.html.erb within layouts/ application (1.3ms) Completed 200 OK in 224ms (Views: 212.4ms | ActiveRecord: 0.0ms)
# For consecutive requests for the same page
Processing by HomeController#index as HTML Completed 304 Not Modified in 2ms (ActiveRecord: 0.0ms) http_cache_forever
@users = User.where(city: 'miami') 1.The query statement doesn’t change. If we change city name from “Miami” to “Boston” then result might change. 2.No record is deleted. 3.No record is added. Caching result sets and collection
@users = User.where(city: 'Miami') @users.cache_key => "users/query-67ed32b36805c4b1ec1948b4eef8d58f-3-20160116111659084027" # users.html.erb cache @users do #content here end Caching result sets and collection