class Rabl::CacheEngine

Public Class Methods

new() click to toggle source
# File lib/rabl/cache_engine.rb, line 31
def initialize
  unless defined?(Rails)
    @cache = LRU.new
  end
end

Public Instance Methods

fetch(key, cache_options) { || ... } click to toggle source

Fetch given a key and options and a fallback block attempts to find the key in the cache and stores the block result in there if no key is found.

cache = ::new; cache.fetch(“some_key”) { “fallback data” }

# File lib/rabl/cache_engine.rb, line 43
def fetch(key, cache_options, &block)
  if defined?(Rails)
    Rails.cache.fetch(key, cache_options, &block)
  else
    @cache[key] ||= yield
  end
end
read_multi(*keys) click to toggle source
# File lib/rabl/cache_engine.rb, line 59
def read_multi(*keys)
  options = keys.extract_options!
  if defined?(Rails)
    Rails.cache.read_multi(*keys, options)
  else
    keys.inject({}) { |hash, key| hash[key] = nil; hash }
  end
end
write(key, value, options = {}) { || ... } click to toggle source
# File lib/rabl/cache_engine.rb, line 51
def write(key, value, options = {})
  if defined?(Rails)
    Rails.cache.write(key, value, options)
  else
    @cache[key] = yield
  end
end