Module: ConcernsOnRails::Controllers::Cacheable::ClassMethods

Defined in:
lib/concerns_on_rails/controllers/cacheable.rb

Instance Method Summary collapse

Instance Method Details

#http_cache_actions(*actions, visibility: :private, max_age: nil, must_revalidate: false, no_store: false, stale_while_revalidate: nil, vary: nil) ⇒ Object

Declare a Cache-Control/Vary policy for the given actions (none = catch-all). Repeatable; rules accumulate (reassigned, never mutated, so subclasses inherit) and the LAST one matching the action wins.



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/concerns_on_rails/controllers/cacheable.rb', line 71

def http_cache_actions(*actions, visibility: :private, max_age: nil, must_revalidate: false,
                       no_store: false, stale_while_revalidate: nil, vary: nil)
  actions = actions.flatten.map(&:to_s)
  visibility = visibility.to_sym
  validate_http_cache!(visibility: visibility, max_age: max_age, no_store: no_store,
                       must_revalidate: must_revalidate, stale_while_revalidate: stale_while_revalidate)

  rule = {
    actions: actions, visibility: visibility,
    max_age: http_cache_seconds(max_age),
    must_revalidate: must_revalidate ? true : false,
    no_store: no_store ? true : false,
    stale_while_revalidate: http_cache_seconds(stale_while_revalidate),
    vary: http_cache_vary(vary)
  }
  self.cacheable_rules = cacheable_rules + [rule]
end