Class: Waves::Caches::Simple
Overview
This class is more or less here to establish the basic interface for caching and for lightweight caching that doesn’t require a dedicated caching process.
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.
12 |
# File 'lib/caches/simple.rb', line 12 def initialize( hash = {} ) ; @cache = hash ; end |
Instance Method Details
#[](key) ⇒ Object
13 |
# File 'lib/caches/simple.rb', line 13 def [](key) ; fetch(key) ; end |
#[]=(key, value) ⇒ Object
14 |
# File 'lib/caches/simple.rb', line 14 def []=( key, value ) ; store( key, value ) ; end |
#clear ⇒ Object
20 |
# File 'lib/caches/simple.rb', line 20 def clear ; @cache = {} ; end |
#delete(key) ⇒ Object
19 |
# File 'lib/caches/simple.rb', line 19 def delete( key ) ; @cache.delete( key ) ; end |
#exists?(key) ⇒ Boolean Also known as: exist?
15 |
# File 'lib/caches/simple.rb', line 15 def exists?( key ) ; fetch(key) == nil ? false : true ; end |
#fetch(key) ⇒ Object
18 |
# File 'lib/caches/simple.rb', line 18 def fetch( key ) ; @cache[ key ] ; end |
#store(key, val) ⇒ Object
17 |
# File 'lib/caches/simple.rb', line 17 def store( key, val ) ; @cache[ key ] = val ; end |