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.


299
300
301
302
# File 'lib/moneta/mixins.rb', line 299

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


368
369
370
371
372
# File 'lib/moneta/mixins.rb', line 368

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


324
325
326
327
# File 'lib/moneta/mixins.rb', line 324

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.


342
343
344
345
# File 'lib/moneta/mixins.rb', line 342

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.

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)


312
313
314
315
# File 'lib/moneta/mixins.rb', line 312

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.

Options Hash (options):

  • :prefix (String)

    Prefix key (See Transformer)

  • Other (Object)

    options as defined by the adapters or middleware


336
337
338
339
# File 'lib/moneta/mixins.rb', line 336

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.


348
349
350
351
# File 'lib/moneta/mixins.rb', line 348

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.


305
306
307
308
309
# File 'lib/moneta/mixins.rb', line 305

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.

Options Hash (options):

  • :prefix (String)

    Prefix key (See Transformer)

  • Other (Object)

    options as defined by the adapters or middleware


330
331
332
333
# File 'lib/moneta/mixins.rb', line 330

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

#key?(key, options = {}) ⇒ Boolean

Exists the value with key

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


354
355
356
357
358
# File 'lib/moneta/mixins.rb', line 354

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

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


361
362
363
364
365
# File 'lib/moneta/mixins.rb', line 361

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.


318
319
320
321
# File 'lib/moneta/mixins.rb', line 318

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