Class: Moneta::Proxy

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

Overview

Proxy base class

Direct Known Subclasses

Expires, Transformer, WeakCreate, WeakIncrement, Wrapper

Instance Attribute 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


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

Instance Method Details

#clear(options = {}) ⇒ void

This method returns an undefined value.

Clear all keys in this store


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

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

#closeObject

Explicitly close the store


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

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.

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)


26
27
28
# File 'lib/moneta/proxy.rb', line 26

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

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


74
75
76
# File 'lib/moneta/proxy.rb', line 74

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

#featuresObject


89
90
91
# File 'lib/moneta/proxy.rb', line 89

def features
  @features ||= (self.class.features + adapter.features).uniq.freeze
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.

Options Hash (options):

  • :prefix (String)

    Prefix key (See Transformer)

  • Other (Object)

    options as defined by the adapters or middleware


21
22
23
# File 'lib/moneta/proxy.rb', line 21

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

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

Exists the value with key

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


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

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


46
47
48
# File 'lib/moneta/proxy.rb', line 46

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

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

Store value with key

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


61
62
63
# File 'lib/moneta/proxy.rb', line 61

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