Class: Shallow::Cache
Instance Method Summary collapse
- #delete(key) ⇒ Object
- #exist?(key) ⇒ Boolean
- #fetch(key) ⇒ Object
-
#initialize ⇒ Cache
constructor
A new instance of Cache.
- #read(key) ⇒ Object
Constructor Details
#initialize ⇒ Cache
Returns a new instance of Cache.
36 37 38 |
# File 'lib/shallow.rb', line 36 def initialize @data_store = {} end |
Instance Method Details
#delete(key) ⇒ Object
50 51 52 |
# File 'lib/shallow.rb', line 50 def delete(key) @data_store.delete(key) end |
#exist?(key) ⇒ Boolean
40 41 42 |
# File 'lib/shallow.rb', line 40 def exist?(key) @data_store.key?(key) end |
#fetch(key) ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/shallow.rb', line 43 def fetch(key) if @data_store.key?(key) @data_store.fetch(key) else @data_store[key] = yield end end |
#read(key) ⇒ Object
53 54 55 |
# File 'lib/shallow.rb', line 53 def read(key) @data_store.fetch(key) end |