Module: Storefront::Helpers::CacheHelper
- Defined in:
- lib/storefront/helpers/cache_helper.rb
Instance Method Summary collapse
- #cached_content(key, &block) ⇒ Object
- #cached_partial(path, locals = {}) ⇒ Object
- #conditional_cache(key, options = {}, &block) ⇒ Object
- #set_cache_buster ⇒ Object
Instance Method Details
#cached_content(key, &block) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/storefront/helpers/cache_helper.rb', line 14 def cached_content(key, &block) if Rails.env.development? yield else fragment_for key do concat yield end end end |
#cached_partial(path, locals = {}) ⇒ Object
4 5 6 7 8 9 10 11 12 |
# File 'lib/storefront/helpers/cache_helper.rb', line 4 def cached_partial(path, locals = {}) if Rails.env.development? render(:partial => path, :locals => locals) else fragment_for path do concat render(:partial => path, :locals => locals) end end end |
#conditional_cache(key, options = {}, &block) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/storefront/helpers/cache_helper.rb', line 24 def conditional_cache(key, = {}, &block) condition = true condition = false if .has_key?(:if) && [:if] != true if condition cache(key, &block) else haml_concat capture_haml(&block) end end |
#set_cache_buster ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/storefront/helpers/cache_helper.rb', line 34 def set_cache_buster if request.xhr? response.headers["Cache-Control"] = "no-cache, no-store, max-age=0, must-revalidate" response.headers["Pragma"] = "no-cache" response.headers["Expires"] = "Fri, 01 Jan 1990 00:00:00 GMT" end end |