BoundedCache#
- class brainstate.util.BoundedCache(maxsize=128)[source]#
A thread-safe LRU cache with bounded size.
This cache stores a limited number of items and evicts the least recently used item when the cache reaches its maximum size. All operations are thread-safe.
- Parameters:
maxsize (
int) – Maximum number of items to store in the cache.
- clear()[source]#
Clear all items from the cache and reset statistics.
This method removes all cached items and resets hit/miss counters to zero.
- Return type:
- get(key, default=None, raise_on_miss=False, error_context='item')[source]#
Get an item from the cache.
- Parameters:
- Returns:
The cached value or the default value.
- Return type:
- Raises:
ValueError – If raise_on_miss is True and the key is not found.
- keys()[source]#
Return all keys in the cache.
- Returns:
A list of all keys currently in the cache.
- Return type: