diff options
author | Seb Bacon <seb.bacon@gmail.com> | 2011-07-25 15:24:58 +0100 |
---|---|---|
committer | Seb Bacon <seb.bacon@gmail.com> | 2011-07-25 15:24:58 +0100 |
commit | 04927e448f99f67bbfde88dd466f03fb23373b28 (patch) | |
tree | fabc9d81ab8d27452bd49c6f988afbd7a3d3644a /app/controllers/application_controller.rb | |
parent | 1e33a67f9e3e282ce83c18127624f74bb5840549 (diff) |
Add cache headers to various pages (in three categories: short, medium, and long).
Diffstat (limited to 'app/controllers/application_controller.rb')
-rw-r--r-- | app/controllers/application_controller.rb | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index fe9ed7ec7..5f18be2e5 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -14,10 +14,32 @@ class ApplicationController < ActionController::Base layout "default" include FastGettext::Translation # make functions like _, n_, N_ etc available) before_filter :set_gettext_locale - + before_filter :set_vary_header # scrub sensitive parameters from the logs filter_parameter_logging :password + def set_vary_header + response.headers['Vary'] = 'Cookie' + end + + helper_method :anonymous_cache, :short_cache, :medium_cache, :long_cache + def anonymous_cache(time) + if session[:user_id].nil? + expires_in time, :public => true + end + end + + def short_cache + anonymous_cache(60.seconds) + end + + def medium_cache + anonymous_cache(60.minutes) + end + + def long_cache + anonymous_cache(24.hours) + end def set_gettext_locale requested_locale = params[:locale] || session[:locale] || cookies[:locale] || request.env['HTTP_ACCEPT_LANGUAGE'] |