Class: Seekmodo::Sdk::Storage::Memory::Cache
- Inherits:
-
Object
- Object
- Seekmodo::Sdk::Storage::Memory::Cache
- Includes:
- Protocols::Cache
- Defined in:
- lib/seekmodo/sdk/storage/memory/stores.rb
Defined Under Namespace
Classes: Entry
Instance Method Summary collapse
- #delete(key) ⇒ Object
- #get(key, default = nil) ⇒ Object
-
#initialize(clock = nil) ⇒ Cache
constructor
A new instance of Cache.
- #set(key, value, ttl_seconds) ⇒ Object
Constructor Details
#initialize(clock = nil) ⇒ Cache
Returns a new instance of Cache.
50 51 52 53 |
# File 'lib/seekmodo/sdk/storage/memory/stores.rb', line 50 def initialize(clock = nil) @rows = {} @clock = clock || -> { Time.now.to_f } end |
Instance Method Details
#delete(key) ⇒ Object
71 72 73 |
# File 'lib/seekmodo/sdk/storage/memory/stores.rb', line 71 def delete(key) @rows.delete(key) end |
#get(key, default = nil) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/seekmodo/sdk/storage/memory/stores.rb', line 55 def get(key, default = nil) entry = @rows[key] return default unless entry if entry.expires_at < @clock.call @rows.delete(key) return default end entry.value end |