Class: ActionController::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/action_controller/macros.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.active_cache(action, *args) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/action_controller/macros.rb', line 3

def self.active_cache(action, *args)
  args = args.extract_options!
  state, condition, expires = args[:state], (args[:if] || lambda{ true}), args[:expires_in]
  before_filter({:only => action}) do |c|
    return unless condition.call(c)
    if p = ActiveCache::cache_store.read(state.call(c).merge!({:action => action}))
      logger.debug "Rendered from memory"
      render(:text => p)
    end
  end

  after_filter({:only => action}) do |c|
    return unless condition.call(c)
    ActiveCache::cache_store.write(state.call(c).merge!({:action => action}), response.body, expires)
  end
end

Instance Method Details

#expire_active_cache(action, hash) ⇒ Object



20
21
22
# File 'lib/action_controller/macros.rb', line 20

def expire_active_cache(action,hash)
  ActiveCache::cache_store.expire(hash.merge!({:action => action}))
end