Cache.pop()
Remove key and return its value, delivering it to exactly one caller.
Usage
Cache.pop(
key,
default=None,
*,
expire_time=False,
tag=False,
retry=False,
)Reads and decodes the value first, as get does, then deletes exactly that stored version, so a value it can’t read stays for whoever can. A pop that loses that delete to other writers 8 times falls back to removing the row first and decoding afterwards. Only then can a failed decode cost the value: one from a newer version, or any error from a pickle hook. timeout covers the whole call.
Parameters
key: Key-
The key.
default: Any = None-
Returned when the key is missing or expired, or its value file is missing.
expire_time: bool = False-
Also return the entry’s expiry time.
tag: bool = False-
Also return the entry’s tag.
retry: bool = False-
On a Timeout, try again until the call gets through, each round with the whole timeout, a
durable=Truehandle included. Only Timeout is retried.
Returns
Any | tuple[Any, Optional[float]] | tuple[Any, Key] | tuple[Any, Optional[float], Key]-
The removed value, or
default; withexpire_timeortag, a tuple as get returns.With
durable=True, a pop whose delete fails returnsdefault, never the value, which could otherwise be delivered twice. The row stays.
Raises
UnsafeValueError-
The value was stored with pickle and this cache has
pickle=False. The row stays. ForeignValueError-
on_decode_error='raise', and another version or host might read the value. The row stays. CorruptValueError-
on_decode_error='raise', and no build could read the value. The row is deleted first. Timeout- Another process held the write lock for longer than timeout, or timeout ran out after losing a race to another writer. This pop deletes nothing, and whatever the other writer left stays.
Examples
token = cache.pop('reset-token:abc') # None if it was missing or already used