Module: Moneta::CreateSupport Private

Included in:
Adapters::LRUHash, Adapters::Memory, WeakCreate
Defined in:
lib/moneta/mixins.rb

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.


400
401
402
# File 'lib/moneta/mixins.rb', line 400

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


391
392
393
394
395
396
397
398
# File 'lib/moneta/mixins.rb', line 391

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