Class: ShopifyClient::Cache::Store Abstract
- Inherits:
-
Object
- Object
- ShopifyClient::Cache::Store
- Defined in:
- lib/shopify-client/cache/store.rb
Overview
This class is abstract.
Direct Known Subclasses
Instance Method Summary collapse
-
#call(key, ttl: ShopifyClient.config.cache_ttl, &block) ⇒ Object
Fetch a value from the cache, falling back to the result of the given block when the cache is empty/expired.
-
#clear(key) ⇒ Object
Clear cached data.
-
#initialize(encode: JSON.method(:generate), decode: JSON.method(:parse)) ⇒ Store
constructor
A new instance of Store.
-
#set(key, value, ttl: ShopifyClient.config.cache_ttl) ⇒ Object
Overwrite cached data and set TTL (if implemented by child class).
Constructor Details
#initialize(encode: JSON.method(:generate), decode: JSON.method(:parse)) ⇒ Store
Returns a new instance of Store.
17 18 19 20 |
# File 'lib/shopify-client/cache/store.rb', line 17 def initialize(encode: JSON.method(:generate), decode: JSON.method(:parse)) @encode = encode @decode = decode end |
Instance Method Details
#call(key, ttl: ShopifyClient.config.cache_ttl, &block) ⇒ Object
Fetch a value from the cache, falling back to the result of the given block when the cache is empty/expired.
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/shopify-client/cache/store.rb', line 29 def call(key, ttl: ShopifyClient.config.cache_ttl, &block) value = get(key) if value.nil? value = block.() set(key, value, ttl: ttl) end value end |
#clear(key) ⇒ Object
Clear cached data.
62 63 64 |
# File 'lib/shopify-client/cache/store.rb', line 62 def clear(key) raise NotImplementedError end |
#set(key, value, ttl: ShopifyClient.config.cache_ttl) ⇒ Object
Overwrite cached data and set TTL (if implemented by child class).
55 56 57 |
# File 'lib/shopify-client/cache/store.rb', line 55 def set(key, value, ttl: ShopifyClient.config.cache_ttl) raise NotImplementedError end |