Class: Mize::DefaultCache
- Inherits:
-
Object
- Object
- Mize::DefaultCache
- Includes:
- CacheProtocol, MonitorMixin
- Defined in:
- lib/mize/default_cache.rb
Instance Method Summary collapse
-
#clear(options = nil) ⇒ Object
Clear the cache by removing all entries from the cache.
-
#delete(name, options = nil) ⇒ Object
Delete a cache entry by name.
-
#each_name(&block) ⇒ self
Each name of the cache is yielded to the block.
-
#exist?(name, options = nil) ⇒ Boolean
Determine whether a cache entry exists in this cache.
-
#initialize ⇒ DefaultCache
constructor
A new instance of DefaultCache.
-
#initialize_dup(other) ⇒ Object
Initialize a duplicate of this cache.
-
#read(name, options = nil) ⇒ Object
Read a value from the cache by name.
-
#write(name, value, options = nil) ⇒ Object
Write a value to the cache by name.
Constructor Details
#initialize ⇒ DefaultCache
Returns a new instance of DefaultCache.
7 8 9 |
# File 'lib/mize/default_cache.rb', line 7 def initialize @data = {} end |
Instance Method Details
#clear(options = nil) ⇒ Object
Clear the cache by removing all entries from the cache
12 13 14 15 |
# File 'lib/mize/default_cache.rb', line 12 def clear( = nil) @data.clear self end |
#delete(name, options = nil) ⇒ Object
Delete a cache entry by name. If the entry does not exist in the cache, it will do nothing.
49 50 51 |
# File 'lib/mize/default_cache.rb', line 49 def delete(name, = nil) @data.delete(name) end |
#each_name(&block) ⇒ self
Each name of the cache is yielded to the block.
55 56 57 58 |
# File 'lib/mize/default_cache.rb', line 55 def each_name(&block) @data.each_key(&block) self end |
#exist?(name, options = nil) ⇒ Boolean
Determine whether a cache entry exists in this cache.
21 22 23 |
# File 'lib/mize/default_cache.rb', line 21 def exist?(name, = nil) @data.key?(name) end |
#initialize_dup(other) ⇒ Object
Initialize a duplicate of this cache.
62 63 64 65 |
# 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) ⇒ Object
Read a value from the cache by name. If the entry does not exist in the cache, it will return nil.
30 31 32 |
# File 'lib/mize/default_cache.rb', line 30 def read(name, = nil) @data.fetch(name, nil) end |
#write(name, value, options = nil) ⇒ Object
Write a value to the cache by name. If an entry with the same name already exists in the cache, it will be overwritten.
40 41 42 |
# File 'lib/mize/default_cache.rb', line 40 def write(name, value, = nil) @data.store(name, value) end |