Class: Moneta::Proxy

Inherits:
Object
  • Object
show all
Includes:
Defaults
Defined in:
lib/moneta/proxy.rb

Overview

Proxy base class

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Defaults

#[], #[]=, #decrement, #fetch, included, #supports?

Methods included from OptionSupport

#expires, #prefix, #raw, #with

Constructor Details

#initialize(adapter, options = {}) ⇒ Proxy

Returns a new instance of Proxy

Parameters:

  • adapter (Moneta store)

    underlying adapter

  • options (Hash) (defaults to: {})

11
12
13
# File 'lib/moneta/proxy.rb', line 11

def initialize(adapter, options = {})
  @adapter = adapter
end

Instance Attribute Details

#adapterObject (readonly)


7
8
9
# File 'lib/moneta/proxy.rb', line 7

def adapter
  @adapter
end

Class Method Details

.features_maskObject

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.


122
123
124
# File 'lib/moneta/proxy.rb', line 122

def features_mask
  @features_mask ||= [].freeze
end

.not_supports(*features) ⇒ Object


127
128
129
130
# File 'lib/moneta/proxy.rb', line 127

def not_supports *features
  @features_mask = (self.features_mask | features).freeze
  super
end

Instance Method Details

#clear(options = {}) ⇒ void

This method returns an undefined value.

Clear all keys in this store

Parameters:

  • options (Hash) (defaults to: {})

93
94
95
96
# File 'lib/moneta/proxy.rb', line 93

def clear(options = {})
  adapter.clear(options)
  self
end

#closeObject

Explicitly close the store

Returns:

  • nil


41
42
43
# File 'lib/moneta/proxy.rb', line 41

def close
  adapter.close
end

#create(key, value, options = {}) ⇒ Boolean

Note:

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.

Parameters:

  • key (Object)
  • value (Object)
  • options (Hash) (defaults to: {})

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)

Returns:

  • (Boolean)

    key was set


36
37
38
# File 'lib/moneta/proxy.rb', line 36

def create(key, value, options = {})
  adapter.create(key, value, options)
end

#delete(key, options = {}) ⇒ Object

Delete the key from the store and return the current value

Parameters:

  • key (Object)
  • options (Hash) (defaults to: {})

Options Hash (options):

  • :raw (Boolean)

    Raw access without value transformation (See Transformer)

  • :prefix (String)

    Prefix key (See Transformer)

  • Other (Object)

    options as defined by the adapters or middleware

Returns:

  • (Object)

    current value


84
85
86
# File 'lib/moneta/proxy.rb', line 84

def delete(key, options = {})
  adapter.delete(key, options)
end

#each_key(&block) ⇒ Enumerator

Note:

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.

Returns:

  • (Enumerator)

    An all-the-keys enumerator


21
22
23
24
25
26
27
28
# File 'lib/moneta/proxy.rb', line 21

def each_key(&block)
  raise NotImplementedError, "each_key is not supported on this proxy" \
    unless supports? :each_key

  return enum_for(:each_key) unless block_given?
  adapter.each_key(&block)
  self
end

#featuresObject


116
117
118
# File 'lib/moneta/proxy.rb', line 116

def features
  @features ||= (self.class.features | adapter.features - self.class.features_mask).freeze
end

#fetch_values(*keys, **options, &defaults) ⇒ Object


102
103
104
# File 'lib/moneta/proxy.rb', line 102

def fetch_values(*keys, **options, &defaults)
  adapter.fetch_values(*keys, **options, &defaults)
end

#increment(key, amount = 1, options = {}) ⇒ Object

Note:

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.

Parameters:

  • key (Object)
  • amount (Integer) (defaults to: 1)
  • options (Hash) (defaults to: {})

Options Hash (options):

  • :prefix (String)

    Prefix key (See Transformer)

  • Other (Object)

    options as defined by the adapters or middleware

Returns:

  • (Object)

    value from store


31
32
33
# File 'lib/moneta/proxy.rb', line 31

def increment(key, amount = 1, options = {})
  adapter.increment(key, amount, options)
end

#key?(key, options = {}) ⇒ Boolean

Exists the value with key

Parameters:

  • key (Object)
  • options (Hash) (defaults to: {})

Options Hash (options):

  • :expires (Integer)

    Update expiration time (See Expires)

  • :prefix (String)

    Prefix key (See Transformer)

  • Other (Object)

    options as defined by the adapters or middleware

Returns:

  • (Boolean)

16
17
18
# File 'lib/moneta/proxy.rb', line 16

def key?(key, options = {})
  adapter.key?(key, options)
end

#load(key, options = {}) ⇒ Object

Fetch value with key. Return nil if the key doesn't exist

Parameters:

  • key (Object)
  • options (Hash) (defaults to: {})

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, Adapters::Daybreak syncs with file)

  • Other (Object)

    options as defined by the adapters or middleware

Returns:

  • (Object)

    value


56
57
58
# File 'lib/moneta/proxy.rb', line 56

def load(key, options = {})
  adapter.load(key, options)
end

#merge!(pairs, options = {}, &block) ⇒ Object


110
111
112
113
# File 'lib/moneta/proxy.rb', line 110

def merge!(pairs, options = {}, &block)
  adapter.merge!(pairs, options, &block)
  self
end

#slice(*keys, **options) ⇒ Object


106
107
108
# File 'lib/moneta/proxy.rb', line 106

def slice(*keys, **options)
  adapter.slice(*keys, **options)
end

#store(key, value, options = {}) ⇒ Object

Store value with key

Parameters:

  • key (Object)
  • value (Object)
  • options (Hash) (defaults to: {})

Options Hash (options):

  • :expires (Integer)

    Set expiration time (See Expires)

  • :raw (Boolean)

    Raw access without value transformation (See Transformer)

  • :prefix (String)

    Prefix key (See Transformer)

  • Other (Object)

    options as defined by the adapters or middleware

Returns:

  • value


71
72
73
# File 'lib/moneta/proxy.rb', line 71

def store(key, value, options = {})
  adapter.store(key, value, options)
end

#values_at(*keys, **options) ⇒ Object


98
99
100
# File 'lib/moneta/proxy.rb', line 98

def values_at(*keys, **options)
  adapter.values_at(*keys, **options)
end