class documentation

class ACMETTLCache(TTLCache):

Constructor: ACMETTLCache(maxsize, ttl, timer, getsizeof, ...)

View In Hierarchy

An improved TTLCache that supports an eviction callback function.

This callback is called whenever an item is evicted from the cache, either due to expiration or because the cache has reached its maximum size.

Method __init__ Initialize the LRUCache.
Method expire Expire items from the cache and call the (optional) eviction callback for each expired item.
Instance Variable _evict The eviction callback function.
def __init__(self, maxsize: int, ttl: Any, timer: Callable = time.monotonic, getsizeof: Callable | None = None, evict: Callable | None = None):

Initialize the LRUCache.

Parameters
maxsize:intThe maximum size of the cache.
ttl:AnyThe time-to-live for cache entries.
timer:CallableUndocumented
getsizeof:Callable | NoneOptional function to determine the size of an item.
evict:Callable | NoneOptional callback function that is called when an item is evicted.
def expire(self, time: float | None = None) -> list[tuple[Any, Any]]:

Expire items from the cache and call the (optional) eviction callback for each expired item.

Parameters
time:float | NoneOptional time to check for expiration. If None, the current time is used.
Returns
list[tuple[Any, Any]]A list of tuples containing the expired key-value pairs.
_evict: Callable | None =

The eviction callback function.