Class: HatiConfig::Cache::MemoryAdapter
- Inherits:
-
Object
- Object
- HatiConfig::Cache::MemoryAdapter
- Defined in:
- lib/hati_config/cache.rb
Overview
MemoryAdapter class provides in-memory caching.
Instance Method Summary collapse
-
#delete(key) ⇒ Object
Deletes a value from the cache.
-
#get(key) ⇒ Object?
Gets a value from the cache.
-
#initialize ⇒ MemoryAdapter
constructor
A new instance of MemoryAdapter.
-
#set(key, value, ttl) ⇒ Object
Sets a value in the cache.
Constructor Details
#initialize ⇒ MemoryAdapter
Returns a new instance of MemoryAdapter.
201 202 203 204 |
# File 'lib/hati_config/cache.rb', line 201 def initialize @store = {} @expiry = {} end |
Instance Method Details
#delete(key) ⇒ Object
Deletes a value from the cache.
229 230 231 232 |
# File 'lib/hati_config/cache.rb', line 229 def delete(key) @store.delete(key) @expiry.delete(key) end |
#get(key) ⇒ Object?
Gets a value from the cache.
210 211 212 213 214 |
# File 'lib/hati_config/cache.rb', line 210 def get(key) return nil if expired?(key) @store[key] end |
#set(key, value, ttl) ⇒ Object
Sets a value in the cache.
221 222 223 224 |
# File 'lib/hati_config/cache.rb', line 221 def set(key, value, ttl) @store[key] = value @expiry[key] = Time.now + ttl if ttl end |