Simple interface to key/value stores with Hash-like interface. @api public
Fetch value with key. Return nil if the key doesn't exist
@param [Object] key @return [Object] value @api public
# File lib/moneta/mixins.rb, line 177 def [](key) load(key) end
Store value with key
@param [Object] key @param [Object] value @return value @api public
# File lib/moneta/mixins.rb, line 187 def []=(key, value) store(key, value) end
Explicitly close the store @return nil @api public
# File lib/moneta/mixins.rb, line 135 def close end
Atomically sets a key to value if it's not set.
@note Not every Moneta store implements this method,
a NotImplementedError is raised if it is not supported.
@param [Object] key @param [Object] value @param [Hash] options @option options [Integer] :expires Update expiration time (See {Expires}) @option options [Boolean] :raw Raw access without value transformation (See {Transformer}) @option options [String] :prefix Prefix key (See {Transformer}) @return [Boolean] key was set @api public
# File lib/moneta/mixins.rb, line 203 def create(key, value, options = {}) raise NotImplementedError, 'create is not supported' end
Atomically decrement integer value with key
This is just syntactic sugar for calling increment with a negative value.
This method also accepts negative amounts.
@param [Object] key @param [Integer] amount @param [Hash] options @option options [String] :prefix Prefix key (See {Transformer}) @option options Other options as defined by the adapters or middleware @return [Object] value from store @api public
# File lib/moneta/mixins.rb, line 128 def decrement(key, amount = 1, options = {}) increment(key, -amount, options) end
Returns features list
@return [Array<Symbol>] list of features
# File lib/moneta/mixins.rb, line 210 def features self.class.features end
Fetch a value with a key
@overload fetch(key, options = {}, &block)
retrieve a key. if the key is not available, execute the block and return its return value. @param [Object] key @param [Hash] options @option options [Integer] :expires Update expiration time (See {Expires}) @option options [Boolean] :raw Raw access without value transformation (See {Transformer}) @option options [String] :prefix Prefix key (See {Transformer}) @return [Object] value from store
@overload fetch(key, default, options = {})
retrieve a key. if the key is not available, return the default value. @param [Object] key @param [Object] default Default value @param [Hash] options @option options [Integer] :expires Update expiration time (See {Expires}) @option options [Boolean] :raw Raw access without value transformation (See {Transformer}) @option options [String] :prefix Prefix key (See {Transformer}) @return [Object] value from store
@api public
# File lib/moneta/mixins.rb, line 161 def fetch(key, default = nil, options = nil) if block_given? raise ArgumentError, 'Only one argument accepted if block is given' if options result = load(key, default || {}) result == nil ? yield(key) : result else result = load(key, options || {}) result == nil ? default : result end end
Atomically increment integer value with key
This method also accepts negative amounts.
@note Not every Moneta store implements this method,
a NotImplementedError is raised if it is not supported.
@param [Object] key @param [Integer] amount @param [Hash] options @option options [String] :prefix Prefix key (See {Transformer}) @option options Other options as defined by the adapters or middleware @return [Object] value from store @api public
# File lib/moneta/mixins.rb, line 111 def increment(key, amount = 1, options = {}) raise NotImplementedError, 'increment is not supported' end
Exists the value with key
@param [Object] key @param [Hash] options @option options [Integer] :expires Update expiration time (See {Expires}) @option options [String] :prefix Prefix key (See {Transformer}) @option options Other options as defined by the adapters or middleware @return [Boolean] @api public
# File lib/moneta/mixins.rb, line 94 def key?(key, options = {}) load(key, options) != nil end
Generated with the Darkfish Rdoc Generator 2.