class Mize::DefaultCache
Public Class Methods
# File lib/mize/default_cache.rb, line 7 def initialize @data = {} end
Public Instance Methods
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 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 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
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 a duplicate of this cache. @param other [Mize::DefaultCache] The other cache to initialize a duplicate of.
# File lib/mize/default_cache.rb, line 62 def initialize_dup(other) super other.instance_variable_set :@data, @data.dup end
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 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