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 = Rabl::CacheEngine.new; cache.fetch(“some_key”) { “fallback data” }
# File lib/rabl/cache_engine.rb, line 16 def fetch(key, cache_options, &block) if defined?(Rails) Rails.cache.fetch(key, cache_options, &block) else yield end end
# File lib/rabl/cache_engine.rb, line 30 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
# File lib/rabl/cache_engine.rb, line 24 def write(key, value, options = {}) if defined?(Rails) Rails.cache.write(key, value, options) end end