Class: Moneta::Adapters::Daybreak
- Inherits:
-
Moneta::Adapter
- Object
- Moneta::Adapter
- Moneta::Adapters::Daybreak
- Includes:
- CreateSupport, DBMAdapter, EachKeySupport, IncrementSupport
- Defined in:
- lib/moneta/adapters/daybreak.rb
Overview
Daybreak backend
Instance Attribute Summary
Attributes included from HashAdapter
Attributes inherited from Moneta::Adapter
Instance Method Summary collapse
-
#create(key, value, options = {}) ⇒ Boolean
Atomically sets a key to value if it’s not set.
-
#increment(key, amount = 1, options = {}) ⇒ Object
Atomically increment integer value with key.
- #initialize(options = {}) ⇒ Object constructor
-
#load(key, options = {}) ⇒ Object
Fetch value with key.
-
#merge!(pairs, options = {}) ⇒ Object
Stores the pairs in the key-value store, and returns itself.
-
#store(key, value, options = {}) ⇒ Object
Store value with key.
Methods included from EachKeySupport
Methods included from CreateSupport
Methods included from IncrementSupport
Methods included from DBMAdapter
Methods included from HashAdapter
#clear, #delete, #fetch_values, #key?, #slice, #values_at
Methods inherited from Moneta::Adapter
backend, backend_block, backend_required?
Methods included from Config
Methods included from Defaults
#[], #[]=, #close, #decrement, #each_key, #features, #fetch, #fetch_values, included, #key?, #slice, #supports?, #update, #values_at
Methods included from OptionSupport
#expires, #prefix, #raw, #with
Constructor Details
#initialize(options = {}) ⇒ Object
17 |
# File 'lib/moneta/adapters/daybreak.rb', line 17 backend { |file:| ::Daybreak::DB.new(file, serializer: ::Daybreak::Serializer::None) } |
Instance Method Details
#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.
38 39 40 |
# File 'lib/moneta/adapters/daybreak.rb', line 38 def create(key, value, = {}) backend.lock { 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.
33 34 35 |
# File 'lib/moneta/adapters/daybreak.rb', line 33 def increment(key, amount = 1, = {}) backend.lock { super } end |
#load(key, options = {}) ⇒ Object
Fetch value with key. Return nil if the key doesn’t exist
20 21 22 23 |
# File 'lib/moneta/adapters/daybreak.rb', line 20 def load(key, = {}) backend.load if [:sync] backend[key] end |
#merge!(pairs, options = {}) ⇒ self #merge!(pairs, options = {}) {|key, old_value, new_value| ... } ⇒ self
Some adapters may implement this method atomically, or in two passes when a block is provided. The default implmentation uses HashAdapter#key?, #load and #store.
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.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/moneta/adapters/daybreak.rb', line 43 def merge!(pairs, = {}) if block_given? backend.lock do backend.update(pairs.map do |key, new_value| new_value = yield(key, load(key), new_value) if key?(key) [key, new_value] end) end else backend.update(pairs) end self end |
#store(key, value, options = {}) ⇒ Object
Store value with key
26 27 28 29 30 |
# File 'lib/moneta/adapters/daybreak.rb', line 26 def store(key, value, = {}) backend[key] = value backend.flush if [:sync] value end |