Class: Jouba::Cache::Memory
- Inherits:
-
Object
- Object
- Jouba::Cache::Memory
- Extended by:
- Forwardable
- Defined in:
- lib/jouba/cache.rb
Instance Attribute Summary collapse
-
#store ⇒ Object
readonly
Returns the value of attribute store.
Class Method Summary collapse
Instance Method Summary collapse
- #fetch(key) ⇒ Object
-
#initialize ⇒ Memory
constructor
A new instance of Memory.
- #refresh(key, value) ⇒ Object
Constructor Details
#initialize ⇒ Memory
Returns a new instance of Memory.
22 23 24 |
# File 'lib/jouba/cache.rb', line 22 def initialize @store = MemoryStore.new end |
Instance Attribute Details
#store ⇒ Object (readonly)
Returns the value of attribute store.
18 19 20 |
# File 'lib/jouba/cache.rb', line 18 def store @store end |
Class Method Details
.load(file_path) ⇒ Object
35 36 37 |
# File 'lib/jouba/cache.rb', line 35 def self.load(file_path) @store = MemoryStore.load(file_path) end |
Instance Method Details
#fetch(key) ⇒ Object
26 27 28 |
# File 'lib/jouba/cache.rb', line 26 def fetch(key) get(key) || yield.tap { |value| store.set(key, value) } end |
#refresh(key, value) ⇒ Object
30 31 32 33 |
# File 'lib/jouba/cache.rb', line 30 def refresh(key, value) store.set(key, value) yield end |