Class: ShopifyClient::Cache::ThreadLocalStore

Inherits:
Store
  • Object
show all
Defined in:
lib/shopify-client/cache/thread_local_store.rb

Instance Method Summary collapse

Methods inherited from Store

#call, #initialize

Constructor Details

This class inherits a constructor from ShopifyClient::Cache::Store

Instance Method Details

#clear(key) ⇒ Object

See Also:



25
26
27
28
# File 'lib/shopify-client/cache/thread_local_store.rb', line 25

def clear(key)
  Thread.current[key] = nil
  Thread.current[build_expiry_key(key)] = nil
end

#get(key) ⇒ Object

See Also:

  • Store#get


7
8
9
10
11
12
13
# File 'lib/shopify-client/cache/thread_local_store.rb', line 7

def get(key)
  return nil if expired?(key)

  value = Thread.current[key]

  @decode.(value) unless value.nil?
end

#set(key, value, ttl: ShopifyClient.config.cache_ttl) ⇒ Object

See Also:



16
17
18
19
20
21
22
# File 'lib/shopify-client/cache/thread_local_store.rb', line 16

def set(key, value, ttl: ShopifyClient.config.cache_ttl)
  Thread.current[key] = @encode.(value)

  if ttl > 0
    Thread.current[build_expiry_key(key)] = Time.now + ttl
  end
end