Class: Feedx::Cache::Memory
- Defined in:
- lib/feedx/cache/memory.rb
Overview
Thread-safe in-memory cache. Use for testing only.
Instance Method Summary collapse
-
#clear ⇒ Object
Clear empties cache.
-
#initialize ⇒ Memory
constructor
A new instance of Memory.
-
#read(key) ⇒ Object
Read reads a key.
-
#write(key, value) ⇒ Object
Write writes a key.
Methods inherited from Abstract
Constructor Details
#initialize ⇒ Memory
Returns a new instance of Memory.
5 6 7 8 |
# File 'lib/feedx/cache/memory.rb', line 5 def initialize @monitor = Monitor.new @entries = {} end |
Instance Method Details
#clear ⇒ Object
Clear empties cache.
11 12 13 14 15 |
# File 'lib/feedx/cache/memory.rb', line 11 def clear @monitor.synchronize do @entries.clear end end |
#read(key) ⇒ Object
Read reads a key.
18 19 20 21 22 |
# File 'lib/feedx/cache/memory.rb', line 18 def read(key, **) @monitor.synchronize do @entries[key] end end |
#write(key, value) ⇒ Object
Write writes a key.
25 26 27 28 29 |
# File 'lib/feedx/cache/memory.rb', line 25 def write(key, value, **) @monitor.synchronize do @entries[key] = value.to_s end end |