Cacheout is a comprehensive caching library for Python, offering in-memory, dictionary-based caching. It supports various eviction policies including FIFO, LIFO, LRU, MRU, LFU, and RR. Key features include configurable maximum cache size, time-to-live (TTL) expiration per entry, thread-safety, bulk operations, and memoization decorators for functions. The library is actively maintained and is currently at version 0.16.0.
pip install cacheoutVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates initializing a Cache, setting and retrieving values, using TTL, and handling missing keys with a callable default.
Ensure your project uses Python 3.7 or a later version.
Replace `cache.setup(...)` with `cache.configure(...)`.
Explicitly set `maxsize` during Cache initialization if a specific size is required (e.g., `Cache(maxsize=300)`).
Update calls to use `cache.get_many(filter=...)` or `cache.delete_many(filter=...)` with appropriate filter arguments (list, string, regex, or function).
Review logic for `Cache.get()` calls where `default` is a callable to ensure this side-effect of setting the value is intended. If not, adjust your logic or use a non-callable default.
Always assume TTL is in seconds unless a custom `timer` function is provided that specifies a different unit.
Install the package using pip: `pip install cacheout`
Ensure that the data used as a cache key or function argument is immutable (e.g., use tuples instead of lists, or convert mutable objects to a hashable representation like a string or an immutable identifier).
Provide an integer value for the 'maxsize' parameter. For example, `Cache(maxsize=100)` or `@memoize(maxsize=50)`.
Set the 'maxsize' parameter to an integer value of 0 or greater. A `maxsize` of 0 means no size limit, but entries will still be evicted if they expire. Setting `maxsize=None` also allows the cache to grow without bound, but entries will not be evicted due to size.
No dependency data recorded yet.