ttlru_map.TTLMap¶
- class ttlru_map.TTLMap(*, ttl: timedelta | None, max_size: int | None = None, update_ttl_on_get: bool = False)¶
A dictionary that removes items after a certain time.
- __init__(*, ttl: timedelta | None, max_size: int | None = None, update_ttl_on_get: bool = False) None¶
Initialize the dictionary.
- Parameters:
max_size – the maximum number of items in the dictionary. 0 means no limit.
ttl – the time to live for each item in the dictionary.
update_ttl_on_get – whether to update the time to live when getting an item.
Methods
__init__(*, ttl[, max_size, update_ttl_on_get])Initialize the dictionary.
clear()get(k[,d])items()keys()pop(k[,d])If key is not found, d is returned if given, otherwise KeyError is raised.
popitem()as a 2-tuple; but raise KeyError if D is empty.
setdefault(k[,d])update([E, ]**F)If E present and has a .keys() method, does: for k in E.keys(): D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k, v in F.items(): D[k] = v
values()