View Source GenCache.CheckCache (gen_cache v0.1.0)
Generic cache layer for anything. Allows concurrent requests without work duplication and blocking.
Usage:
{:ok, pid} = GenCache.CheckCache.start_link()
# populate cache with default `ttl` value
response = GenCache.CheckCache.request(pid, {Mod, :fun, [arg1, arg2]})
# populate cache with custom `ttl` value
response = GenCache.CheckCache.request(pid, {Mod, :fun, [arg1, arg2]}, ttl: :timer.seconds(15))
Special notes:
- we use a map to signify the state of the cache (usually this is an atom)
- this map contains currently running cache misses
- every change on this map triggers a state transition in gen_statem
- the postponed requests get a chance to run again on each state transition