class Mize::DefaultCache

Public Class Methods

new() click to toggle source
# File lib/mize/default_cache.rb, line 7
def initialize
  @data = {}
end

Public Instance Methods

clear(options = nil) click to toggle source

Clear the cache by removing all entries from the cache

# File lib/mize/default_cache.rb, line 12
def clear(options = nil)
  @data.clear
  self
end
delete(name, options = nil) click to toggle source

Delete a cache entry by name. If the entry does not exist in the cache, it will do nothing.

@param name [String] The name of the cache entry to delete. @return [Object] The value stored in the chache before deletion.

# File lib/mize/default_cache.rb, line 49
def delete(name, options = nil)
  @data.delete(name)
end
each_name(&block) click to toggle source

Each name of the cache is yielded to the block. @return [self]

# File lib/mize/default_cache.rb, line 55
def each_name(&block)
  @data.each_key(&block)
  self
end
exist?(name, options = nil) click to toggle source

Determine whether a cache entry exists in this cache.

@param name [String] The name of the cache entry to check. @return [Boolean] Whether or not the cache entry exists.

# File lib/mize/default_cache.rb, line 21
def exist?(name, options = nil)
  @data.key?(name)
end
initialize_dup(other) click to toggle source

Initialize a duplicate of this cache. @param other [Mize::DefaultCache] The other cache to initialize a duplicate of.

Calls superclass method
# File lib/mize/default_cache.rb, line 62
def initialize_dup(other)
  super
  other.instance_variable_set :@data, @data.dup
end
read(name, options = nil) click to toggle source

Read a value from the cache by name. If the entry does not exist in the cache, it will return nil.

@param name [String] The name of the cache entry to read. @return [Object] The value stored in the cache for the given name.

# File lib/mize/default_cache.rb, line 30
def read(name, options = nil)
  @data.fetch(name, nil)
end
write(name, value, options = nil) click to toggle source

Write a value to the cache by name. If an entry with the same name already exists in the cache, it will be overwritten.

@param name [String] The name of the cache entry to write. @param value [Object] The value to store in the cache for the given name. @return [Object] The value stored in the chache.

# File lib/mize/default_cache.rb, line 40
def write(name, value, options = nil)
  @data.store(name, value)
end