Class: Mistri::Locks::Memory
- Inherits:
-
Object
- Object
- Mistri::Locks::Memory
- Defined in:
- lib/mistri/locks.rb
Overview
The in-process adapter: real TTL semantics over a hash, for tests, development, and the thread dispatcher. Monitor-synchronized; expiry is judged at read time, so nothing needs a sweeper.
Instance Method Summary collapse
- #acquire(key, ttl:) ⇒ Object
- #clear_flag(key) ⇒ Object
- #flag?(key) ⇒ Boolean
- #held?(key) ⇒ Boolean
-
#initialize ⇒ Memory
constructor
A new instance of Memory.
- #release(key) ⇒ Object
- #renew(key, ttl:) ⇒ Object
- #set_flag(key, ttl: 300) ⇒ Object
Constructor Details
#initialize ⇒ Memory
Returns a new instance of Memory.
89 90 91 92 |
# File 'lib/mistri/locks.rb', line 89 def initialize @entries = {} @lock = Monitor.new end |
Instance Method Details
#acquire(key, ttl:) ⇒ Object
94 95 96 97 98 99 100 101 |
# File 'lib/mistri/locks.rb', line 94 def acquire(key, ttl:) @lock.synchronize do return false if live?(key) @entries[key] = deadline(ttl) true end end |
#clear_flag(key) ⇒ Object
123 |
# File 'lib/mistri/locks.rb', line 123 def clear_flag(key) = release(key) |
#flag?(key) ⇒ Boolean
121 |
# File 'lib/mistri/locks.rb', line 121 def flag?(key) = held?(key) |
#held?(key) ⇒ Boolean
113 114 115 |
# File 'lib/mistri/locks.rb', line 113 def held?(key) @lock.synchronize { live?(key) } end |
#release(key) ⇒ Object
108 109 110 111 |
# File 'lib/mistri/locks.rb', line 108 def release(key) @lock.synchronize { @entries.delete(key) } nil end |
#renew(key, ttl:) ⇒ Object
103 104 105 106 |
# File 'lib/mistri/locks.rb', line 103 def renew(key, ttl:) @lock.synchronize { @entries[key] = deadline(ttl) } nil end |
#set_flag(key, ttl: 300) ⇒ Object
117 118 119 |
# File 'lib/mistri/locks.rb', line 117 def set_flag(key, ttl: 300) renew(key, ttl: ttl) end |