Module: CacheProxy::Common

Included in:
ClassMethods, InstanceMethods
Defined in:
lib/cache_proxy.rb

Instance Method Summary collapse

Instance Method Details

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



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/cache_proxy.rb', line 10

def cache_proxy(key, options = {}, &block)
  options.reverse_merge!({
    :cached => true,
    :cache_expires_in => 30.days
  })

  repository = options[:repository] || Rails.cache

  if options[:cached]
    repository.fetch(key, :expires_in => options[:cache_expires_in], &block)
  else
    yield
  end
end