Module: Moneta::EachKeySupport Private

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.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.prepended(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.


373
374
375
376
# File 'lib/moneta/mixins.rb', line 373

def self.prepended(base)
  base.supports(:each_key) if base.respond_to?(:supports)
  require 'set'
end

Instance Method Details

#[](key) ⇒ Object

Fetch value with key. Return nil if the key doesn't exist

Parameters:

  • key (Object)

Returns:

  • (Object)

    value


442
443
444
445
446
# File 'lib/moneta/mixins.rb', line 442

def [](key)
  value = super
  if value.nil? then all_keys.delete(key) else each_key_save(key) end
  value
end

#[]=(key, value) ⇒ Object

Store value with key

Parameters:

  • key (Object)
  • value (Object)

Returns:

  • value


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

def []=(key, value)
  each_key_save(key)
  super
end

#clear(options = {}) ⇒ 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.


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

def clear(options = {})
  all_keys.clear
  super
end

#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 Moneta::Expires)

  • :raw (Boolean)

    Raw access without value transformation (See Transformer)

  • :prefix (String)

    Prefix key (See Transformer)

Returns:

  • (Boolean)

    key was set


386
387
388
389
# File 'lib/moneta/mixins.rb', line 386

def create(key, value, options = {})
  each_key_save(key)
  super
end

#decrement(key, amount = 1, options = {}) ⇒ Object

Atomically decrement integer value with key

This is just syntactic sugar for calling #increment with a negative value.

This method also accepts negative amounts.

Parameters:

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

Options Hash (options):

  • :prefix (String)

    Prefix key (See Transformer)

  • Other (Object)

    options as defined by the adapters or middleware

Returns:

  • (Object)

    value from store


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

def decrement(key, amount = 1, options = {})
  each_key_save(key)
  super
end

#delete(key, options = {}) ⇒ 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.


422
423
424
425
# File 'lib/moneta/mixins.rb', line 422

def delete(key, options = {})
  all_keys.delete(key)
  super
end

#each_keyEnumerator

Note:

Not every Moneta store implements this method, a NotImplementedError is raised if it is not supported.

Calls block once for each key in store, passing the key as a parameter. If no block is given, an enumerator is returned instead.

Returns:

  • (Enumerator)

    An all-the-keys enumerator


379
380
381
382
383
# File 'lib/moneta/mixins.rb', line 379

def each_key
  return enum_for(:each_key) unless block_given?
  all_keys.each{ |k| yield(k) }
  self
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: {})

Options Hash (options):

  • :prefix (String)

    Prefix key (See Transformer)

  • Other (Object)

    options as defined by the adapters or middleware

Returns:

  • (Object)

    value from store


404
405
406
407
# File 'lib/moneta/mixins.rb', line 404

def increment(key, amount = 1, options = {})
  each_key_save(key)
  super
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 Transformer)

  • Other (Object)

    options as defined by the adapters or middleware

Returns:

  • (Boolean)

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

def key?(key, options = {})
  found = super
  if found then each_key_save(key) else all_keys.delete(key) end
  found
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 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


435
436
437
438
439
# File 'lib/moneta/mixins.rb', line 435

def load(key, options = {})
  value = super
  if value.nil? then all_keys.delete(key) else each_key_save(key) end
  value
end

#store(key, value, options = {}) ⇒ 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.


392
393
394
395
# File 'lib/moneta/mixins.rb', line 392

def store(key, value, options = {})
  each_key_save(key)
  super
end