module JustimmoClient::V1::JustimmoInterface
Public Instance Methods
cache_key(endpoint, params = {})
click to toggle source
# File lib/justimmo_client/api/v1/interfaces/justimmo_interface.rb, line 9 def cache_key(endpoint, params = {}) key = Digest::SHA256.new key << endpoint key << params.to_s key.hexdigest end
with_cache(key, on_hit:, on_miss:, **options)
click to toggle source
# File lib/justimmo_client/api/v1/interfaces/justimmo_interface.rb, line 16 def with_cache(key, on_hit:, on_miss:, **options) log.debug("Looking up cache key #{key}") data = nil cached = cache.read(key) if cached.nil? log.debug("Cache miss for #{key}") data, new_cache = on_miss.call() cache.write(key, new_cache, options) else log.debug("Cache hit for #{key}") data = on_hit.call(cached) end data end