Cache.get()
Return the value stored for key, or default if it’s missing or expired.
Usage
Cache.get(
key,
default=None,
*,
expire_time=False,
)Reads never write, so any number of threads and processes can read at once.
Parameters
key: str-
The key to look up.
default: Any = None-
Returned when the key is missing or expired.
expire_time: bool = False- Also return the entry’s expiry time.
Returns
Any | tuple[Any, float | None]-
The value, or
default. Withexpire_time=True, a(value, expire_time)tuple, whereexpire_timeis a Unix timestamp, or None for an entry that never expires (or a miss).
Raises
UnsafeValueError-
The value was stored with pickle and this cache has
pickle=False. CorruptValueError-
The stored bytes can’t be decoded.
Timeout-
Reading a large value kept losing to concurrent overwrites until timeout, or a pending fork outlasted it.
durable=Truereturnsdefaultinstead.
Examples
user = cache.get('user:42') # None on a miss
user = cache.get('user:42', default={}) # {} on a miss
value, expires_at = cache.get('user:42', expire_time=True)