Registry / database / cacheout

cacheout

JSON →
library0.16.0pypypi✓ verified 23d ago

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 cacheout
INSTALL
IMPORT
SIG · CACHEOUT
C
cacheout
databasepythonv0.16.0
Install
1.6s avg
Import
218ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.16.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.234s · 17.9MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.6s · import 0.202s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Cache
from cacheout import Cache
CacheManager
from cacheout import CacheManager
memoize
from cacheout import memoize
FIFOCache
from cacheout import FIFOCache
Other specific cache types (LIFOCache, LRUCache, MRUCache, LFUCAche, RRCache) are imported similarly.

This quickstart demonstrates initializing a Cache, setting and retrieving values, using TTL, and handling missing keys with a callable default.

from cacheout import Cache import time # Initialize a cache with a max size and default TTL (in seconds) cache = Cache(maxsize=100, ttl=60) # Set a value cache.set('key1', 'value1') # Get a value print(f"Value for key1: {cache.get('key1')}") # Set a value with a custom TTL (overriding the default) cache.set('key2', 'value2', ttl=5) # Check cache size and keys print(f"Cache size: {cache.size()}") print(f"Cache keys: {cache.keys()}") # Wait for key2 to expire time.sleep(6) # Try to get expired key (will return None by default) print(f"Value for key2 after 6 seconds: {cache.get('key2')}") # Use a callable default for missing keys (and set it if missing) print(f"Value for key3 (missing): {cache.get('key3', default=lambda k: f'computed_for_{k}')}") print(f"Value for key3 (now cached): {cache.get('key3')}")
Debug
Known issues
breakingPython 3.6 support was dropped in v0.14.0. Users must upgrade to Python 3.7 or newer to use cacheout >= 0.14.0.
fix
Ensure your project uses Python 3.7 or a later version.
affects: >= 0.14.0
breakingThe `Cache.setup()` method was renamed to `Cache.configure()` in v0.2.0. Direct calls to `setup()` will no longer work.
fix
Replace `cache.setup(...)` with `cache.configure(...)`.
affects: >= 0.2.0
breakingThe default `Cache.maxsize` changed from 300 to 256 in v0.7.0. If your application relied on the previous default, this might lead to earlier evictions.
fix
Explicitly set `maxsize` during Cache initialization if a specific size is required (e.g., `Cache(maxsize=300)`).
affects: >= 0.7.0
breakingIn v0.9.0, `Cache.get_many_by()` and `Cache.delete_many_by()` were removed, and their functionality merged into `Cache.get_many()` and `Cache.delete_many()` respectively.
fix
Update calls to use `cache.get_many(filter=...)` or `cache.delete_many(filter=...)` with appropriate filter arguments (list, string, regex, or function).
affects: >= 0.9.0
breakingIn v0.10.0, the behavior of the `default` argument in `Cache.get()` when it's a callable changed. If the key is missing and `default` is a callable, its return value will now be set in the cache for that key.
fix
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.
affects: >= 0.10.0
gotchaTTL values are in seconds by default, as the default timer function is `time.time`. Be mindful of this unit when setting `ttl` values for caches or individual entries.
fix
Always assume TTL is in seconds unless a custom `timer` function is provided that specifies a different unit.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'cacheout'
The 'cacheout' Python package is not installed in the active environment.
fix
Install the package using pip: `pip install cacheout`
TypeError: unhashable type: 'DataFrame'
Cache keys or arguments to memoized functions must be hashable. Mutable objects like lists, dictionaries, and Pandas DataFrames are not hashable by default.
fix
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).
TypeError: maxsize must be an integer
The 'maxsize' parameter, used for initializing a Cache object or a memoization decorator, was provided with a non-integer value.
fix
Provide an integer value for the 'maxsize' parameter. For example, `Cache(maxsize=100)` or `@memoize(maxsize=50)`.
ValueError: maxsize must be greater than or equal to 0
The 'maxsize' parameter for a Cache object or memoization decorator was set to a negative integer.
fix
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.
Upgrade
Version history
0.16.0latest on PyPI · released Dec 22, 2023
Audit
Dependencies

No dependency data recorded yet.

Agent activity
16 hits · last 30 days
node
14
OpenAI (training)
1
Resources
cacheout — pip install cacheout · libregistry