Module: Cacheable::ModelFetch

Included in:
Cacheable
Defined in:
lib/cacheable/model_fetch.rb

Instance Method Summary collapse

Instance Method Details

#fetch(key, options = nil) ⇒ Object



3
4
5
6
7
8
9
10
11
# File 'lib/cacheable/model_fetch.rb', line 3

def fetch(key, options=nil)
  unless result = read(key, options)
    if block_given?
      result = yield
      write(key, result, options) unless result.nil?
    end
  end
  result
end