Cache and ScopedCache: effectful lookups shared by key.
A cache runs lookup(key) the first time a key is asked for and shares
the outcome, success or failure, with every later caller. Callers asking
while a lookup runs wait for that one lookup::
users = yield from fx.Cache.make(fetch_user, capacity=1000, time_to_live=60)
user = yield from users.get(user_id)capacity: the most entries kept; the least recently used go first (get,get_optionandget_successcount as a use;hasdoes not).time_to_live: a duration, or a function of the lookup'sExitand the key, read from theClockwhen the lookup ends. Zero keeps nothing in aCache; the default is forever. Expired entries are dropped when next read.ScopedCache: each entry's lookup runs in a scope of its own, closed when the entry leaves the cache, and every entry's when the scope the cache was made in closes.
Keys compare with == and hash: use frozen dataclasses or tuples
for structured keys.
Classes#
On This Page
Classes