Module: Moneta::HashAdapter Private

Included in:
Adapters::LocalMemCache, Adapters::Memory, Adapters::TokyoTyrant
Defined in:
lib/moneta/mixins.rb

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.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#backendObject (readonly)

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.


407
408
409
# File 'lib/moneta/mixins.rb', line 407

def backend
  @backend
end

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.


453
454
455
# File 'lib/moneta/mixins.rb', line 453

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

Instance Method Details

#clear(options = {}) ⇒ void

This method returns an undefined value.

Clear all keys in this store

Parameters:

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

430
431
432
433
# File 'lib/moneta/mixins.rb', line 430

def clear(options = {})
  @backend.clear
  self
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 Transformer)

  • :prefix (String)

    Prefix key (See Transformer)

  • Other (Object)

    options as defined by the adapters or middleware

Returns:

  • (Object)

    current value


425
426
427
# File 'lib/moneta/mixins.rb', line 425

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

#each_key(&block) ⇒ 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.


435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
# File 'lib/moneta/mixins.rb', line 435

def each_key(&block)
  return enum_for(:each_key) unless block_given?

  if @backend.respond_to?(:each_key)
    @backend.each_key(&block)
  elsif @backend.respond_to?(:keys)
    if keys = @backend.keys
      keys.each(&block)
    end
  elsif @backend.respond_to?(:each)
    @backend.each { |k| yield(k) }
  else
    raise ::NotImplementedError, "No enumerator found on backend"
  end

  self
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 Expires)

  • :prefix (String)

    Prefix key (See Transformer)

  • Other (Object)

    options as defined by the adapters or middleware

Returns:

  • (Boolean)

410
411
412
# File 'lib/moneta/mixins.rb', line 410

def key?(key, options = {})
  @backend.has_key?(key)
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 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

Returns:

  • (Object)

    value


415
416
417
# File 'lib/moneta/mixins.rb', line 415

def load(key, options = {})
  @backend[key]
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 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

Returns:

  • value


420
421
422
# File 'lib/moneta/mixins.rb', line 420

def store(key, value, options = {})
  @backend[key] = value
end