Module: Nitro::Caching::Actions::ClassMethods

Defined in:
lib/nitro/caching/actions.rb

Instance Method Summary collapse

Instance Method Details

#cache_action(*actions) ⇒ Object

Cache the given actions.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/nitro/caching/actions.rb', line 26

def cache_action(*actions)
  return unless caching_enabled?
  
  before(
    %{
      fragment_name = "\#\{@action_name\}\#{@request.query_string}"
      if fragment = Fragments.get(fragment_name)
        @out = fragment
        return
      end
    },
    :only => actions
  )
  
  after(
    %{ 
      fragment_name = "\#\{@action_name\}\#{@request.query_string}"
      Fragments.put(fragment_name, @out) 
    },
    :only => actions
  )
end