Class: Waves::Caches::Simple
Overview
A simple in-memory cache. This also serves as the base class for all the Waves caching implementations, so that descendents only need to override #initialize, #fetch, #store, #delete, and #clear, since the other methods are defined in terms of those.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #clear ⇒ Object
- #delete(key) ⇒ Object
- #exists?(key) ⇒ Boolean (also: #exist?)
- #fetch(key) ⇒ Object
-
#initialize(hash = {}) ⇒ Simple
constructor
A new instance of Simple.
- #store(key, val) ⇒ Object
Constructor Details
#initialize(hash = {}) ⇒ Simple
Returns a new instance of Simple.
11 |
# File 'lib/waves/caches/simple.rb', line 11 def initialize( hash = {} ) ; @cache = hash ; end |
Instance Method Details
#[](key) ⇒ Object
12 |
# File 'lib/waves/caches/simple.rb', line 12 def [](key) ; fetch(key) ; end |
#[]=(key, value) ⇒ Object
13 |
# File 'lib/waves/caches/simple.rb', line 13 def []=( key, value ) ; store( key, value ) ; end |
#clear ⇒ Object
19 |
# File 'lib/waves/caches/simple.rb', line 19 def clear ; @cache = {} ; end |
#delete(key) ⇒ Object
18 |
# File 'lib/waves/caches/simple.rb', line 18 def delete( key ) ; @cache.delete( key ) ; end |
#exists?(key) ⇒ Boolean Also known as: exist?
14 |
# File 'lib/waves/caches/simple.rb', line 14 def exists?( key ) ; fetch(key) == nil ? false : true ; end |
#fetch(key) ⇒ Object
17 |
# File 'lib/waves/caches/simple.rb', line 17 def fetch( key ) ; @cache[ key ] ; end |
#store(key, val) ⇒ Object
16 |
# File 'lib/waves/caches/simple.rb', line 16 def store( key, val ) ; @cache[ key ] = val ; end |