Class: APICache::MemoryStore
- Inherits:
-
AbstractStore
- Object
- AbstractStore
- APICache::MemoryStore
- Defined in:
- lib/api_cache/memory_store.rb
Instance Method Summary collapse
- #created_at(key) ⇒ Object
- #delete(key) ⇒ Object
- #exists?(key) ⇒ Boolean
- #get(key) ⇒ Object
-
#initialize(cache = {}) ⇒ MemoryStore
constructor
A new instance of MemoryStore.
- #set(key, value) ⇒ Object
Methods inherited from AbstractStore
Constructor Details
#initialize(cache = {}) ⇒ MemoryStore
Returns a new instance of MemoryStore.
3 4 5 6 7 |
# File 'lib/api_cache/memory_store.rb', line 3 def initialize(cache = {}) APICache.logger.debug "Using memory store" @cache = cache true end |
Instance Method Details
#created_at(key) ⇒ Object
29 30 31 |
# File 'lib/api_cache/memory_store.rb', line 29 def created_at(key) @cache[key] && @cache[key][0] end |
#delete(key) ⇒ Object
21 22 23 |
# File 'lib/api_cache/memory_store.rb', line 21 def delete(key) @cache.delete(key) end |
#exists?(key) ⇒ Boolean
25 26 27 |
# File 'lib/api_cache/memory_store.rb', line 25 def exists?(key) !@cache[key].nil? end |
#get(key) ⇒ Object
15 16 17 18 19 |
# File 'lib/api_cache/memory_store.rb', line 15 def get(key) data = exists?(key) ? @cache[key][1] : nil APICache.logger.debug("cache: #{data.nil? ? "miss" : "hit"} (#{key})") data end |
#set(key, value) ⇒ Object
9 10 11 12 13 |
# File 'lib/api_cache/memory_store.rb', line 9 def set(key, value) APICache.logger.debug("cache: set (#{key})") @cache[key] = [Time.now, value] true end |