Class: Moneta::Adapters::MongoBase Private

Inherits:
Object
  • Object
show all
Includes:
Defaults, ExpiresSupport
Defined in:
lib/moneta/adapters/mongo/base.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Direct Known Subclasses

MongoMoped, MongoOfficial

Constant Summary collapse

DEFAULT_PORT =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

27017

Instance Attribute Summary collapse

Attributes included from ExpiresSupport

#default_expires

Instance Method Summary collapse

Methods included from Defaults

#[], #[]=, #close, #create, #decrement, #each_key, #features, #fetch, included, #increment, #key?, #merge!, #slice, #supports?, #update

Methods included from OptionSupport

#expires, #prefix, #raw, #with

Constructor Details

#initialize(options = {}) ⇒ MongoBase

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of MongoBase


15
16
17
18
19
20
# File 'lib/moneta/adapters/mongo/base.rb', line 15

def initialize(options = {})
  self.default_expires = options.delete(:expires)
  @expires_field = options.delete(:expires_field) || 'expiresAt'
  @value_field = options.delete(:value_field) || 'value'
  @type_field = options.delete(:type_field) || 'type'
end

Instance Attribute Details

#backendObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


11
12
13
# File 'lib/moneta/adapters/mongo/base.rb', line 11

def backend
  @backend
end

Instance Method Details

#fetch_values(*keys, **options) ⇒ Object #fetch_values(*keys, **options) {|key| ... } ⇒ Array<Object, nil>

Note:

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.

Overloads:

  • #fetch_values(*keys, **options) {|key| ... } ⇒ Array<Object, nil>

    Returns Array containing the values requested, or where keys are missing, the return values from the corresponding block calls

    Yield Parameters:

    • key (Object)

      Each key that is not found in the store

    Yield Returns:

    • (Object, nil)

      The value to substitute for the missing one


23
24
25
26
27
28
29
30
31
32
33
# File 'lib/moneta/adapters/mongo/base.rb', line 23

def fetch_values(*keys, **options)
  return values_at(*keys, **options) unless block_given?
  hash = Hash[slice(*keys, **options)]
  keys.map do |key|
    if hash.key?(key)
      hash[key]
    else
      yield key
    end
  end
end

#values_at(*keys, **options) ⇒ Array<Object, nil>

Note:

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.

Options Hash (**options):

  • :expires (Integer)

    Update expiration time (See Expires)

  • :raw (Boolean)

    Raw access without value transformation (See Transformer)

  • :prefix (String)

    Prefix key (See Transformer)

  • :sync (Boolean)

    Synchronized load (Cache reloads from adapter, Daybreak syncs with file)

  • Other (Object)

    options as defined by the adapters or middleware


36
37
38
39
# File 'lib/moneta/adapters/mongo/base.rb', line 36

def values_at(*keys, **options)
  hash = Hash[slice(*keys, **options)]
  keys.map { |key| hash[key] }
end