Class: Memorize::Action::MemorizeFilter

Inherits:
Object
  • Object
show all
Defined in:
lib/memorize/action.rb

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ MemorizeFilter

Returns a new instance of MemorizeFilter.



26
27
28
29
30
31
# File 'lib/memorize/action.rb', line 26

def initialize(options)
  @cache_path = options.delete(:cache_path)
  @key_builder = options.delete(:key_builder)
  @key_param = options.delete(:key_param)
  @key_params = options.delete(:params) || []
end

Instance Method Details

#after(cache_path, controller) ⇒ Object



50
51
52
# File 'lib/memorize/action.rb', line 50

def after(cache_path, controller)
  Memorize.cache_store.write cache_path, controller.response.body
end

#before(cache_path, controller) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/memorize/action.rb', line 42

def before(cache_path, controller)
  if (cache = Memorize.cache_store.read(cache_path))
    options = {:layout => false, :text => cache}
    controller.__send__(:render, options)
  end
  !!cache
end

#filter(controller, action) ⇒ Object



33
34
35
36
37
38
39
40
# File 'lib/memorize/action.rb', line 33

def filter(controller, action)
  cache_path = eval_cache_path(controller)
  cached = before(cache_path, controller)
  unless cached
    action.call
    after(cache_path, controller) if caching_allowed?(controller)
  end
end