Module: PackRat::CacheHelper::Cacher

Defined in:
lib/pack_rat.rb

Instance Method Summary collapse

Instance Method Details

#cache(key = '', options = {}, &block) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/pack_rat.rb', line 15

def cache(key='', options={}, &block)
  unless options[:overwrite_key]
    calling_method = caller[0][/`([^']*)'/, 1]
    key << calling_method << '/'
    key << self.cache_key << '/'
    if self.is_a? Class
      key << self.file_digest
    else
      key << self.class.file_digest
    end
  end
  puts key if options[:debug]
  filtered_options = options.except(:overwrite_key, :debug)
  Rails.cache.fetch key, filtered_options do
    block.call
  end
end