Module: Modular::Components::Caching

Defined in:
lib/modular/caching.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



4
5
6
7
8
9
10
11
12
13
# File 'lib/modular/caching.rb', line 4

def self.included(base)
  base.cattr_accessor :cache_options
  
  base.class_eval do
    def self.cache(*args, &block)
      self.cache_options = args.extract_options!
      self.cache_options[:cache_key] = block if block_given?
    end
  end
end

Instance Method Details

#cache_optionsObject



31
32
33
# File 'lib/modular/caching.rb', line 31

def cache_options
  self.class.cache_options
end

#cache_storeObject



27
28
29
# File 'lib/modular/caching.rb', line 27

def cache_store
  ::ActionController::Base.cache_store
end

#clear_cacheObject



35
36
37
# File 'lib/modular/caching.rb', line 35

def clear_cache
  cache_store.delete cache_key
end

#renderObject



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/modular/caching.rb', line 15

def render
  if cache_options.nil?
    super
  elsif cached?
    get_cached
  else
    data = super
    do_caching data
    data
  end
end