class Sprockets::Cache

def fetch(key)

Returns a JSON serializable object.

cache.fetch("foo") { "bar" }

Examples

Must return a consistent JSON serializable object for the given key.
block -
key - JSON serializable key

Public: Prefer API to retrieve and set values in the cache store.
def fetch(key)
  start = Time.now.to_f
  expanded_key = expand_key(key)
  value = @fetch_cache.get(expanded_key)
  if value.nil?
    value = @cache_wrapper.get(expanded_key)
    if value.nil?
      value = yield
      @cache_wrapper.set(expanded_key, value)
      @logger.debug do
        ms = "(#{((Time.now.to_f - start) * 1000).to_i}ms)"
        "Sprockets Cache miss #{peek_key(key)}  #{ms}"
      end
    end
    @fetch_cache.set(expanded_key, value)
  end
  value
end