Skip to content

Instantly share code, notes, and snippets.

@harlow
Created April 16, 2014 22:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save harlow/10938652 to your computer and use it in GitHub Desktop.
Save harlow/10938652 to your computer and use it in GitHub Desktop.
Rails 4 cache_control headers
def set_cache_control_headers(max_age = 1.second.to_s)
if request.method == "GET"
request.session_options[:skip] = true
response.cache_control[:public] = true
response.cache_control[:extras] = ['no-cache']
response.headers['Surrogate-Control'] = "max-age=#{max_age}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment