Class: Juno::Cache
Overview
Combines two stores. One is used as cache, the other as backend.
Defined Under Namespace
Classes: DSL
Instance Attribute Summary collapse
- #backend ⇒ Object readonly
- #cache ⇒ Object readonly
Instance Method Summary collapse
- #clear(options = {}) ⇒ Object
- #close ⇒ Object
- #delete(key, options = {}) ⇒ Object
-
#initialize(options = {}, &block) ⇒ Cache
constructor
A new instance of Cache.
- #key?(key, options = {}) ⇒ Boolean
- #load(key, options = {}) ⇒ Object
- #store(key, value, options = {}) ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(options = {}, &block) ⇒ Cache
Returns a new instance of Cache.
40 41 42 |
# File 'lib/juno/cache.rb', line 40 def initialize( = {}, &block) @cache, @backend = DSL.new(, &block).result end |
Instance Attribute Details
#backend ⇒ Object (readonly)
38 39 40 |
# File 'lib/juno/cache.rb', line 38 def backend @backend end |
#cache ⇒ Object (readonly)
38 39 40 |
# File 'lib/juno/cache.rb', line 38 def cache @cache end |
Instance Method Details
#clear(options = {}) ⇒ Object
67 68 69 70 71 |
# File 'lib/juno/cache.rb', line 67 def clear( = {}) @cache.clear() @backend.clear() self end |
#close ⇒ Object
73 74 75 76 |
# File 'lib/juno/cache.rb', line 73 def close @cache.close @backend.close end |
#delete(key, options = {}) ⇒ Object
62 63 64 65 |
# File 'lib/juno/cache.rb', line 62 def delete(key, = {}) @cache.delete(key, ) @backend.delete(key, ) end |
#key?(key, options = {}) ⇒ Boolean
44 45 46 |
# File 'lib/juno/cache.rb', line 44 def key?(key, = {}) @cache.key?(key, ) || @backend.key?(key, ) end |
#load(key, options = {}) ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/juno/cache.rb', line 48 def load(key, = {}) value = @cache.load(key, ) unless value value = @backend.load(key, ) @cache.store(key, value, ) if value end value end |
#store(key, value, options = {}) ⇒ Object
57 58 59 60 |
# File 'lib/juno/cache.rb', line 57 def store(key, value, = {}) @cache.store(key, value, ) @backend.store(key, value, ) end |