Class: Persistent::StorageRAM
- Inherits:
-
Persistent::Storage::API
- Object
- Persistent::Storage::API
- Persistent::StorageRAM
- Defined in:
- lib/persistent-cache/storage_ram.rb
Instance Attribute Summary collapse
-
#storage ⇒ Object
Returns the value of attribute storage.
Instance Method Summary collapse
- #clear ⇒ Object
- #delete_entry(serialized_key) ⇒ Object
-
#initialize(storage_details = nil) ⇒ StorageRAM
constructor
A new instance of StorageRAM.
- #keys ⇒ Object
- #lookup_key(serialized_key) ⇒ Object
- #save_key_value_pair(serialized_key, serialized_value, timestamp = nil) ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize(storage_details = nil) ⇒ StorageRAM
Returns a new instance of StorageRAM.
10 11 12 |
# File 'lib/persistent-cache/storage_ram.rb', line 10 def initialize(storage_details = nil) @storage = {} end |
Instance Attribute Details
#storage ⇒ Object
Returns the value of attribute storage.
8 9 10 |
# File 'lib/persistent-cache/storage_ram.rb', line 8 def storage @storage end |
Instance Method Details
#clear ⇒ Object
48 49 50 51 52 |
# File 'lib/persistent-cache/storage_ram.rb', line 48 def clear EH.retry!(:args => []) do @storage.clear end end |
#delete_entry(serialized_key) ⇒ Object
29 30 31 32 33 |
# File 'lib/persistent-cache/storage_ram.rb', line 29 def delete_entry(serialized_key) EH.retry!(:args => [serialized_key]) do @storage.delete(serialized_key) end end |
#keys ⇒ Object
41 42 43 44 45 46 |
# File 'lib/persistent-cache/storage_ram.rb', line 41 def keys EH.retry!(:args => []) do return [] if @storage.keys == [] [@storage.keys] end end |
#lookup_key(serialized_key) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/persistent-cache/storage_ram.rb', line 22 def lookup_key(serialized_key) EH.retry!(:args => [serialized_key]) do return [] if @storage[serialized_key].nil? [@storage[serialized_key][:value], @storage[serialized_key][:timestamp]] end end |
#save_key_value_pair(serialized_key, serialized_value, timestamp = nil) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/persistent-cache/storage_ram.rb', line 14 def save_key_value_pair(serialized_key, serialized_value, = nil) delete_entry(serialized_key) time_entry = .nil? ? Time.now.to_s : .to_s EH.retry!(:args => [serialized_key, serialized_value, time_entry]) do @storage[serialized_key] = {:value => serialized_value, :timestamp => time_entry} end end |
#size ⇒ Object
35 36 37 38 39 |
# File 'lib/persistent-cache/storage_ram.rb', line 35 def size EH.retry!(:args => []) do @storage.size end end |