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, Wrapper

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Defaults

#[], #[]=, #decrement, #fetch

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

Instance Method Details

#clear(options = {}) ⇒ void

This method returns an undefined value.

Clear all keys in this store

Parameters:

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


77
78
79
80
# File 'lib/moneta/proxy.rb', line 77

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

#closeObject

Explicitly close the store

Returns:

  • nil



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

def close
  adapter.close
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 ‘Moneta::Transformer`)

  • :prefix (String)

    Prefix key (See ‘Moneta::Transformer`)

  • Other (Object)

    options as defined by the adapters or middleware

Returns:

  • (Object)

    current value



68
69
70
# File 'lib/moneta/proxy.rb', line 68

def delete(key, options = {})
  adapter.delete(key, options)
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: {})

Returns:

  • (Object)

    value from store



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

Parameters:

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

Options Hash (options):

  • :expires (Integer)

    Update expiration time (See ‘Moneta::Expires`)

  • :prefix (String)

    Prefix key (See ‘Moneta::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 ‘Moneta::Expires`)

  • :raw (Boolean)

    Raw access without value transformation (See ‘Moneta::Transformer`)

  • :prefix (String)

    Prefix key (See ‘Moneta::Transformer`)

  • Other (Object)

    options as defined by the adapters or middleware

Returns:

  • (Object)

    value



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

def load(key, options = {})
  adapter.load(key, 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 ‘Moneta::Expires`)

  • :raw (Boolean)

    Raw access without value transformation (See ‘Moneta::Transformer`)

  • :prefix (String)

    Prefix key (See ‘Moneta::Transformer`)

  • Other (Object)

    options as defined by the adapters or middleware

Returns:

  • value



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

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