Class: AtomicCache::Storage::SharedMemory
- Defined in:
- lib/atomic_cache/storage/shared_memory.rb
Overview
A storage adapter which keeps all values in memory, global to all threads
Constant Summary collapse
- STORE =
{}
- SEMAPHORE =
Mutex.new
Class Attribute Summary collapse
-
.enforce_ttl ⇒ Object
Returns the value of attribute enforce_ttl.
Class Method Summary collapse
Instance Method Summary collapse
- #add(raw_key, new_value, ttl, user_options = {}) ⇒ Object
- #reset ⇒ Object
- #store ⇒ Object
- #store_op(key, user_options = {}) ⇒ Object
Methods inherited from Memory
Methods inherited from Store
Class Attribute Details
.enforce_ttl ⇒ Object
Returns the value of attribute enforce_ttl.
15 16 17 |
# File 'lib/atomic_cache/storage/shared_memory.rb', line 15 def enforce_ttl @enforce_ttl end |
Class Method Details
.reset ⇒ Object
28 29 30 |
# File 'lib/atomic_cache/storage/shared_memory.rb', line 28 def self.reset STORE.clear end |
.store ⇒ Object
32 33 34 |
# File 'lib/atomic_cache/storage/shared_memory.rb', line 32 def self.store STORE end |
Instance Method Details
#add(raw_key, new_value, ttl, user_options = {}) ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/atomic_cache/storage/shared_memory.rb', line 18 def add(raw_key, new_value, ttl, ={}) if self.class.enforce_ttl super(raw_key, new_value, ttl, ) else store_op(raw_key, ) do |key, | write(key, new_value, ttl, ) end end end |
#reset ⇒ Object
36 37 38 |
# File 'lib/atomic_cache/storage/shared_memory.rb', line 36 def reset self.class.reset end |
#store ⇒ Object
40 41 42 |
# File 'lib/atomic_cache/storage/shared_memory.rb', line 40 def store STORE end |
#store_op(key, user_options = {}) ⇒ Object
44 45 46 47 48 49 |
# File 'lib/atomic_cache/storage/shared_memory.rb', line 44 def store_op(key, ={}) normalized_key = key.to_sym SEMAPHORE.synchronize do yield(normalized_key, ) end end |