Class: QueuePulse::MemoryStore
- Inherits:
-
Object
- Object
- QueuePulse::MemoryStore
- Defined in:
- lib/queue_pulse/memory_store.rb
Overview
Minimal in-process cache used as a fallback when Rails.cache is unavailable (e.g. plain Ruby tests, or apps with no cache store configured).
Implements the small subset of the ActiveSupport::Cache interface QueuePulse relies on: #read, #write (with :expires_in), #delete. Thread-safe.
Defined Under Namespace
Classes: Entry
Instance Method Summary collapse
- #delete(key) ⇒ Object
-
#initialize ⇒ MemoryStore
constructor
A new instance of MemoryStore.
- #read(key) ⇒ Object
- #write(key, value, expires_in: nil) ⇒ Object
Constructor Details
#initialize ⇒ MemoryStore
Returns a new instance of MemoryStore.
12 13 14 15 |
# File 'lib/queue_pulse/memory_store.rb', line 12 def initialize @data = {} @mutex = Mutex.new end |
Instance Method Details
#delete(key) ⇒ Object
37 38 39 40 |
# File 'lib/queue_pulse/memory_store.rb', line 37 def delete(key) @mutex.synchronize { @data.delete(key) } true end |
#read(key) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/queue_pulse/memory_store.rb', line 17 def read(key) @mutex.synchronize do entry = @data[key] return nil unless entry if entry.expires_at && entry.expires_at <= monotonic_now @data.delete(key) return nil end entry.value end end |