Module: Padrino::Cache::Helpers::ObjectCache

Defined in:
padrino-cache/lib/padrino-cache/helpers/cache_object.rb

Instance Method Summary collapse

Instance Method Details

#cache_object(key, opts = {}) ⇒ Object


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'padrino-cache/lib/padrino-cache/helpers/cache_object.rb', line 5

def cache_object(key, opts = {})
  if settings.caching?
    began_at = Time.now
    if settings.cache.key?(key.to_s)
      value = settings.cache[key.to_s]
      logger.debug "GET Object", began_at, key.to_s if defined?(logger)
    else
      value = yield
      settings.cache.store(key.to_s, value, opts)
      logger.debug "SET Object", began_at, key.to_s if defined?(logger)
    end
    value
  else
    yield
  end
end