Module: JustimmoClient::V1::JustimmoInterface
Instance Method Summary
collapse
Methods included from Logging
default_logger, #logger, rails_logger
Methods included from Caching
#cache, default_cache
Instance Method Details
#cache_key(endpoint, params = {}) ⇒ Object
8
9
10
11
12
13
|
# File 'lib/justimmo_client/api/v1/interfaces/justimmo_interface.rb', line 8
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) ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/justimmo_client/api/v1/interfaces/justimmo_interface.rb', line 15
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
|