Class: Moneta::Stack
Overview
Combines multiple stores. Reads return the result from the first store, writes go to all stores.
Defined Under Namespace
Classes: DSL
Instance Attribute Summary collapse
- #stack ⇒ Object readonly
Instance Method Summary collapse
-
#clear(options = {}) ⇒ void
Clear all keys in this store.
- #close ⇒ Object
-
#delete(key, options = {}) ⇒ Object
Delete the key from the store and return the current value.
- #increment(key, amount = 1, options = {}) ⇒ Object
-
#initialize(options = {}, &block) ⇒ Stack
constructor
A new instance of Stack.
- #key?(key, options = {}) ⇒ Boolean
-
#load(key, options = {}) ⇒ Object
Fetch value with key.
-
#store(key, value, options = {}) ⇒ Object
Store value with key.
Methods included from Defaults
#[], #[]=, #decrement, #fetch
Methods included from OptionSupport
#expires, #prefix, #raw, #with
Constructor Details
Instance Attribute Details
#stack ⇒ Object (readonly)
35 36 37 |
# File 'lib/moneta/stack.rb', line 35 def stack @stack end |
Instance Method Details
#clear(options = {}) ⇒ void
This method returns an undefined value.
Clear all keys in this store
77 78 79 80 |
# File 'lib/moneta/stack.rb', line 77 def clear( = {}) @stack.each {|s| s.clear() } self end |
#close ⇒ Object
83 84 85 86 |
# File 'lib/moneta/stack.rb', line 83 def close @stack.each {|s| s.close } nil end |
#delete(key, options = {}) ⇒ Object
Delete the key from the store and return the current value
69 70 71 72 73 74 |
# File 'lib/moneta/stack.rb', line 69 def delete(key, = {}) @stack.inject(nil) do |value, s| v = s.delete(key, ) value || v end end |
#increment(key, amount = 1, options = {}) ⇒ Object
62 63 64 65 66 |
# File 'lib/moneta/stack.rb', line 62 def increment(key, amount = 1, = {}) last = nil @stack.each {|s| last = s.increment(key, amount, ) } last end |
#key?(key, options = {}) ⇒ Boolean
42 43 44 |
# File 'lib/moneta/stack.rb', line 42 def key?(key, = {}) @stack.any? {|s| s.key?(key, ) } end |
#load(key, options = {}) ⇒ Object
Fetch value with key. Return nil if the key doesn’t exist
47 48 49 50 51 52 53 |
# File 'lib/moneta/stack.rb', line 47 def load(key, = {}) @stack.each do |s| value = s.load(key, ) return value if value != nil end nil end |
#store(key, value, options = {}) ⇒ Object
Store value with key
56 57 58 59 |
# File 'lib/moneta/stack.rb', line 56 def store(key, value, = {}) @stack.each {|s| s.store(key, value, ) } value end |