Class: APICache::MonetaStore
- Inherits:
-
AbstractStore
- Object
- AbstractStore
- APICache::MonetaStore
- Defined in:
- lib/api_cache/moneta_store.rb
Instance Method Summary (collapse)
-
- (Boolean) exists?(key)
Does a given key exist in the cache?.
-
- (Boolean) expired?(key, timeout)
Has a given time passed since the key was set?.
-
- (Object) get(key)
Get value.
-
- (MonetaStore) initialize(store)
constructor
A new instance of MonetaStore.
-
- (Object) set(key, value)
Set value.
Constructor Details
- (MonetaStore) initialize(store)
A new instance of MonetaStore
3 4 5 |
# File 'lib/api_cache/moneta_store.rb', line 3 def initialize(store) @moneta = store end |
Instance Method Details
- (Boolean) exists?(key)
Does a given key exist in the cache?
20 21 22 |
# File 'lib/api_cache/moneta_store.rb', line 20 def exists?(key) @moneta.key?(key) end |
- (Boolean) expired?(key, timeout)
Has a given time passed since the key was set?
25 26 27 |
# File 'lib/api_cache/moneta_store.rb', line 25 def expired?(key, timeout) Time.now - @moneta["#{key}_created_at"] > timeout end |
- (Object) get(key)
Get value.
15 16 17 |
# File 'lib/api_cache/moneta_store.rb', line 15 def get(key) @moneta[key] end |
- (Object) set(key, value)
Set value. Returns true if success.
8 9 10 11 12 |
# File 'lib/api_cache/moneta_store.rb', line 8 def set(key, value) @moneta[key] = value @moneta["#{key}_created_at"] = Time.now true end |