Class: Moneta::Wrapper
Overview
Wraps the calls to the adapter
Direct Known Subclasses
Fallback, Lock, Logger, OptionMerger, Pool, Shared, WeakEachKey
Instance Attribute Summary
Attributes inherited from Proxy
Instance Method Summary collapse
-
#clear(options = {}) ⇒ void
Clear all keys in this store.
-
#close ⇒ Object
Explicitly close the store.
-
#create(key, value, options = {}) ⇒ Boolean
Atomically sets a key to value if it’s not set.
-
#delete(key, options = {}) ⇒ Object
Delete the key from the store and return the current value.
-
#each_key(&block) ⇒ Object
Calls block once for each key in store, passing the key as a parameter.
-
#features ⇒ Array<Symbol>
Returns features list.
-
#fetch_values(*keys, **options, &defaults) ⇒ Object
Behaves identically to #values_at except that it accepts an optional block.
-
#increment(key, amount = 1, options = {}) ⇒ Object
Atomically increment integer value with key.
-
#key?(key, options = {}) ⇒ Boolean
Exists the value with key.
-
#load(key, options = {}) ⇒ Object
Fetch value with key.
-
#merge!(pairs, options = {}) ⇒ Object
Stores the pairs in the key-value store, and returns itself.
-
#slice(*keys, **options) ⇒ <(Object, Object)>
Returns a collection of key-value pairs corresponding to those supplied keys which are present in the key-value store, and their associated values.
-
#store(key, value, options = {}) ⇒ Object
Store value with key.
-
#values_at(*keys, **options) ⇒ Array<Object, nil>
Returns an array containing the values associated with the given keys, in the same order as the supplied keys.
Methods inherited from Proxy
features_mask, #initialize, not_supports
Methods included from Defaults
#[], #[]=, #decrement, #fetch, included, #supports?, #update
Methods included from OptionSupport
#expires, #prefix, #raw, #with
Constructor Details
This class inherits a constructor from Moneta::Proxy
Instance Method Details
#clear(options = {}) ⇒ void
This method returns an undefined value.
Clear all keys in this store
36 37 38 |
# File 'lib/moneta/wrapper.rb', line 36 def clear( = {}) wrap(:clear, ) { super } end |
#close ⇒ Object
Explicitly close the store
41 42 43 |
# File 'lib/moneta/wrapper.rb', line 41 def close wrap(:close) { super } end |
#create(key, value, options = {}) ⇒ Boolean
Not every Moneta store implements this method, a NotImplementedError is raised if it is not supported.
Atomically sets a key to value if it’s not set.
31 32 33 |
# File 'lib/moneta/wrapper.rb', line 31 def create(key, value, = {}) wrap(:create, key, value, ) { super } end |
#delete(key, options = {}) ⇒ Object
Delete the key from the store and return the current value
21 22 23 |
# File 'lib/moneta/wrapper.rb', line 21 def delete(key, = {}) wrap(:delete, key, ) { super } end |
#each_key ⇒ Enumerator #each_key {|key| ... } ⇒ self
Not every Moneta store implements this method, a NotImplementedError is raised if it is not supported.
Calls block once for each key in store, passing the key as a parameter. If no block is given, an enumerator is returned instead.
51 52 53 |
# File 'lib/moneta/wrapper.rb', line 51 def each_key(&block) wrap(:each_key) { super } end |
#features ⇒ Array<Symbol>
Returns features list
46 47 48 |
# File 'lib/moneta/wrapper.rb', line 46 def features wrap(:features) { super } end |
#fetch_values(*keys, **options) ⇒ Object #fetch_values(*keys, **options) {|key| ... } ⇒ Array<Object, nil>
Some adapters may implement this method atomically. The default implmentation uses #values_at.
Behaves identically to #values_at except that it accepts an optional block. When supplied, the block will be called successively with each supplied key that is not present in the store. The return value of the block call will be used in place of nil in returned the array of values.
61 62 63 |
# File 'lib/moneta/wrapper.rb', line 61 def fetch_values(*keys, **, &defaults) wrap(:fetch_values, keys, , defaults) { super } end |
#increment(key, amount = 1, options = {}) ⇒ Object
Not every Moneta store implements this method, a NotImplementedError is raised if it is not supported.
Atomically increment integer value with key
This method also accepts negative amounts.
26 27 28 |
# File 'lib/moneta/wrapper.rb', line 26 def increment(key, amount = 1, = {}) wrap(:increment, key, amount, ) { super } end |
#key?(key, options = {}) ⇒ Boolean
Exists the value with key
6 7 8 |
# File 'lib/moneta/wrapper.rb', line 6 def key?(key, = {}) wrap(:key?, key, ) { super } end |
#load(key, options = {}) ⇒ Object
Fetch value with key. Return nil if the key doesn’t exist
11 12 13 |
# File 'lib/moneta/wrapper.rb', line 11 def load(key, = {}) wrap(:load, key, ) { super } end |
#merge!(pairs, options = {}) ⇒ self #merge!(pairs, options = {}) {|key, old_value, new_value| ... } ⇒ self
Stores the pairs in the key-value store, and returns itself. When a block is provided, it will be called before overwriting any existing values with the key, old value and supplied value, and the return value of the block will be used in place of the supplied value.
71 72 73 |
# File 'lib/moneta/wrapper.rb', line 71 def merge!(pairs, = {}) wrap(:merge!, pairs, ) { super } end |
#slice(*keys, **options) ⇒ <(Object, Object)>
The keys in the return value may be the same objects that were supplied (i.e. Object#equal?), or may simply be equal (i.e. Object#==).
Some adapters may implement this method atomically. The default implmentation uses #values_at.
Returns a collection of key-value pairs corresponding to those supplied keys which are present in the key-value store, and their associated values. Only those keys present in the store will have pairs in the return value. The return value can be any enumerable object that yields pairs, so it could be a hash, but needn’t be.
66 67 68 |
# File 'lib/moneta/wrapper.rb', line 66 def slice(*keys, **) wrap(:slice, keys, ) { super } end |
#store(key, value, options = {}) ⇒ Object
Store value with key
16 17 18 |
# File 'lib/moneta/wrapper.rb', line 16 def store(key, value, = {}) wrap(:store, key, value, ) { super } end |
#values_at(*keys, **options) ⇒ Array<Object, nil>
Some adapters may implement this method atomically, but the default implementation simply makes repeated calls to #load.
Returns an array containing the values associated with the given keys, in the same order as the supplied keys. If a key is not present in the key-value-store, nil is returned in its place.
56 57 58 |
# File 'lib/moneta/wrapper.rb', line 56 def values_at(*keys, **) wrap(:values_at, keys, ) { super } end |