Class: Rabl::CacheEngine
- Inherits:
-
Object
- Object
- Rabl::CacheEngine
- Defined in:
- lib/rabl/cache_engine.rb
Instance Method Summary collapse
-
#fetch(key, cache_options, &block) ⇒ Object
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.
- #read_multi(*keys) ⇒ Object
- #write(key, value, options = {}) ⇒ Object
Instance Method Details
#fetch(key, cache_options, &block) ⇒ Object
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” }
16 17 18 19 20 21 22 |
# File 'lib/rabl/cache_engine.rb', line 16 def fetch(key, , &block) if defined?(Rails) Rails.cache.fetch(key, , &block) else yield end end |
#read_multi(*keys) ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/rabl/cache_engine.rb', line 30 def read_multi(*keys) = keys. if defined?(Rails) Rails.cache.read_multi(*keys, ) else keys.inject({}) { |hash, key| hash[key] = nil; hash } end end |
#write(key, value, options = {}) ⇒ Object
24 25 26 27 28 |
# File 'lib/rabl/cache_engine.rb', line 24 def write(key, value, = {}) if defined?(Rails) Rails.cache.write(key, value, ) end end |