Class: Caches::InMemory
- Inherits:
-
Object
- Object
- Caches::InMemory
- Defined in:
- lib/store/caches/in_memory.rb
Instance Method Summary collapse
-
#initialize ⇒ InMemory
constructor
A new instance of InMemory.
- #invalidate ⇒ Object
- #load(key) ⇒ Object
- #save(key, data) ⇒ Object
Constructor Details
#initialize ⇒ InMemory
Returns a new instance of InMemory.
4 5 6 |
# File 'lib/store/caches/in_memory.rb', line 4 def initialize @cache = {} end |
Instance Method Details
#invalidate ⇒ Object
8 9 10 |
# File 'lib/store/caches/in_memory.rb', line 8 def invalidate @cache = {} end |
#load(key) ⇒ Object
12 13 14 15 16 17 |
# File 'lib/store/caches/in_memory.rb', line 12 def load(key) data = @cache[key] if data Marshal.load(data) end end |
#save(key, data) ⇒ Object
19 20 21 |
# File 'lib/store/caches/in_memory.rb', line 19 def save key, data @cache[key] = Marshal.dump(data) end |