Module: PackRat::CacheHelper::Cacher

Defined in:
lib/pack_rat/cache_helper/cacher.rb

Instance Method Summary collapse

Instance Method Details

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



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/pack_rat/cache_helper/cacher.rb', line 4

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.dup
  filtered_options.delete(:debug)
  filtered_options.delete(:overwrite_key)
  Rails.cache.fetch key, filtered_options do
    block.call
  end
end