Class: APICache::MemoryStore
- Inherits:
-
AbstractStore
- Object
- AbstractStore
- APICache::MemoryStore
- Defined in:
- lib/api_cache/memory_store.rb
Instance Method Summary (collapse)
- - (Boolean) exists?(key)
- - (Boolean) expired?(key, timeout)
- - (Object) get(key)
-
- (MemoryStore) initialize
constructor
A new instance of MemoryStore.
- - (Object) set(key, value)
Constructor Details
- (MemoryStore) initialize
A new instance of MemoryStore
3 4 5 6 7 |
# File 'lib/api_cache/memory_store.rb', line 3 def initialize APICache.logger.debug "Using memory store" @cache = {} true end |
Instance Method Details
- (Boolean) exists?(key)
21 22 23 |
# File 'lib/api_cache/memory_store.rb', line 21 def exists?(key) !@cache[key].nil? end |
- (Boolean) expired?(key, timeout)
25 26 27 |
# File 'lib/api_cache/memory_store.rb', line 25 def expired?(key, timeout) Time.now - created(key) > timeout end |
- (Object) get(key)
15 16 17 18 19 |
# File 'lib/api_cache/memory_store.rb', line 15 def get(key) data = @cache[key][1] APICache.logger.debug("cache: #{data.nil? ? "miss" : "hit"} (#{key})") data end |
- (Object) set(key, value)
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 |