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.



461
462
463
# File 'lib/moneta/mixins.rb', line 461

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



452
453
454
455
456
457
458
459
# File 'lib/moneta/mixins.rb', line 452

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