Class: Lucid::Shopify::Cache

Inherits:
Object
  • Object
show all
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.12.0'

Instance Method Summary collapse

Instance Method Details

#add_namespace(new_namespace) ⇒ Cache Also known as: +

Create a new instance with a new namespace appended to the current one.

Examples:

cache.add_namespace(myshopify_domain)

Using the #+ operator alias

cache + myshopify_domain


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.

Yield Returns:

  • (#to_cbor)


45
46
47
48
49
# File 'lib/lucid/shopify/cache.rb', line 45

def call(key, ttl: TTL)
  key = namespaced_key(key)

  fetch(key) || cache(key, yield, ttl)
end

#clear(key) ⇒ Object



80
81
82
# File 'lib/lucid/shopify/cache.rb', line 80

def clear(key)
  redis_client.del(namespaced_key(key))
end

#namespaceString



15
# File 'lib/lucid/shopify/cache.rb', line 15

param :namespace, default: proc { 'lucid/shopify-cache' }

#redis_clientRedis



17
# File 'lib/lucid/shopify/cache.rb', line 17

option :redis_client, default: proc { Redis.current }