Class: LucidShopify::Cache
- Inherits:
-
Object
- Object
- LucidShopify::Cache
- Extended by:
- Dry::Initializer
- Defined in:
- lib/lucid_shopify/cache.rb,
lib/lucid_shopify/cache/version.rb
Constant Summary collapse
- TTL =
ENV['LUCID_SHOPIFY_CACHE_TTL'] || 3600
- VERSION =
'0.9.0'
Instance Method Summary collapse
-
#add_namespace(new_namespace) ⇒ Cache
(also: #+)
Create a new instance with a new namespace appended to the current one.
-
#call(key, ttl: TTL) ⇒ Object
Fetch value from the cache, falling back to the given block when the cache is empty.
- #clear(key) ⇒ Object
- #namespace ⇒ String
- #redis_client ⇒ Redis
Instance Method Details
#add_namespace(new_namespace) ⇒ Cache Also known as: +
Create a new instance with a new namespace appended to the current one.
30 31 32 |
# File 'lib/lucid_shopify/cache.rb', line 30 def add_namespace(new_namespace) self.class.new("#{namespace}:#{new_namespace}", redis_client) end |
#call(key, ttl: TTL) ⇒ Object
Fetch value from the cache, falling back to the given block when the cache is empty.
47 48 49 50 51 |
# File 'lib/lucid_shopify/cache.rb', line 47 def call(key, ttl: TTL) key = namespaced_key(key) fetch(key) || cache(key, yield, ttl) end |
#clear(key) ⇒ Object
90 91 92 |
# File 'lib/lucid_shopify/cache.rb', line 90 def clear(key) redis_client.del(namespaced_key(key)) end |
#namespace ⇒ String
13 |
# File 'lib/lucid_shopify/cache.rb', line 13 param :namespace, default: proc { 'lucid_shopify-cache' } |
#redis_client ⇒ Redis
15 |
# File 'lib/lucid_shopify/cache.rb', line 15 option :redis_client, default: proc { Redis.current } |