Implement various cache algorithms
masterThe cachetools module provides several cache implementations based on different eviction algorithms. All cache classes derive from Cache (which inherits from collections.abc.MutableMapping) and support maxsize and currsize properties.
Important Notes:
maxsizemust be a positive number. Usemath.inffor an unbounded cache.- Cache size is determined by the sum of the sizes of its values. You can provide a custom
getsizeof(value) -> intcallable to the constructor to define how item size is calculated. - Thread Safety: Cache classes are not thread-safe. Use a
lockobject with memoizing decorators to synchronize access in multi-threaded environments.