Class: AtomicCache::Storage::Memory
- Inherits:
-
Store
- Object
- Store
- AtomicCache::Storage::Memory
show all
- Defined in:
- lib/atomic_cache/storage/memory.rb
Overview
An abstract storage adapter which keeps all values in memory
Instance Method Summary
collapse
Instance Method Details
#add(raw_key, new_value, ttl, user_options = {}) ⇒ Object
17
18
19
20
21
22
|
# File 'lib/atomic_cache/storage/memory.rb', line 17
def add(raw_key, new_value, ttl, user_options={})
store_op(raw_key, user_options) do |key, options|
return false if store.has_key?(key) && !ttl_expired?(store[key])
write(key, new_value, ttl, user_options)
end
end
|
#delete(raw_key) ⇒ Object
47
48
49
50
51
52
|
# File 'lib/atomic_cache/storage/memory.rb', line 47
def delete(raw_key)
store_op(raw_key) do |key, options|
store.delete(key)
true
end
end
|
#read(raw_key, user_options = {}) ⇒ Object
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/atomic_cache/storage/memory.rb', line 24
def read(raw_key, user_options={})
store_op(raw_key, user_options) do |key, options|
entry = store[key]
return nil unless entry.present?
unmarshaled = unmarshal(entry[:value], user_options)
return unmarshaled if entry[:ttl].nil? or entry[:ttl] == false
if ttl_expired?(entry)
store.delete(key)
nil
else
unmarshaled
end
end
end
|
#set(raw_key, new_value, user_options = {}) ⇒ Object
41
42
43
44
45
|
# File 'lib/atomic_cache/storage/memory.rb', line 41
def set(raw_key, new_value, user_options={})
store_op(raw_key, user_options) do |key, options|
write(key, new_value, options[:expires_in], user_options)
end
end
|
#store ⇒ Object
This method is abstract.
implement returning a Hash of the in-memory representation
12
|
# File 'lib/atomic_cache/storage/memory.rb', line 12
def store; raise NotImplementedError end
|
#store_op(key, user_options = {}) ⇒ Object
This method is abstract.
implement performing an operation on the store
15
|
# File 'lib/atomic_cache/storage/memory.rb', line 15
def store_op(key, user_options={}); raise NotImplementedError end
|