Class: ShopifyClient::CachedRequest
- Inherits:
-
Object
- Object
- ShopifyClient::CachedRequest
- Defined in:
- lib/shopify-client/cached_request.rb
Overview
Caching for GET requests.
Instance Method Summary collapse
-
#call(client) ⇒ Hash
Response data.
-
#clear(myshopify_domain) ⇒ Object
Clear the cached data for a given shop.
- #default_store ⇒ Cache::Store
-
#initialize(path, params: {}, store: default_store) ⇒ CachedRequest
constructor
A new instance of CachedRequest.
-
#set(myshopify_domain, data) ⇒ Object
Overwrite cached data for a given shop.
Constructor Details
#initialize(path, params: {}, store: default_store) ⇒ CachedRequest
Returns a new instance of CachedRequest.
16 17 18 19 20 |
# File 'lib/shopify-client/cached_request.rb', line 16 def initialize(path, params: {}, store: default_store) @path = path @params = params @store = store end |
Instance Method Details
#call(client) ⇒ Hash
Returns response data.
34 35 36 37 38 |
# File 'lib/shopify-client/cached_request.rb', line 34 def call(client) @store.(build_key(client.myshopify_domain)) do client.get(@path, @params).data end end |
#clear(myshopify_domain) ⇒ Object
Clear the cached data for a given shop.
65 66 67 |
# File 'lib/shopify-client/cached_request.rb', line 65 def clear(myshopify_domain) @store.clear(build_key(myshopify_domain)) end |
#default_store ⇒ Cache::Store
23 24 25 26 27 28 29 |
# File 'lib/shopify-client/cached_request.rb', line 23 def default_store if defined?(Redis) Cache::RedisStore.new else Cache::ThreadLocalStore.new end end |
#set(myshopify_domain, data) ⇒ Object
Overwrite cached data for a given shop. This might be used when the data is received from a webhook.
58 59 60 |
# File 'lib/shopify-client/cached_request.rb', line 58 def set(myshopify_domain, data) @store.set(build_key(myshopify_domain), data) end |