Module: Moneta::CreateSupport Private

Overview

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

Implements simple create using key? and store.

This is sufficient for non-shared stores or if atomicity is not required.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

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.



17
18
19
# File 'lib/moneta/create_support.rb', line 17

def self.included(base)
  base.supports(:create) if base.respond_to?(:supports)
end

Instance Method Details

#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



8
9
10
11
12
13
14
15
# File 'lib/moneta/create_support.rb', line 8

def create(key, value, options = {})
  if key? key
    false
  else
    store(key, value, options)
    true
  end
end