tooluniverse.cache package

Cache utilities for ToolUniverse.

Submodules

tooluniverse.cache.memory_cache module

In-memory cache utilities for ToolUniverse.

Provides a lightweight, thread-safe LRU cache with optional singleflight deduplication for expensive misses.

class tooluniverse.cache.memory_cache.LRUCache[source]

Bases: object

Thread-safe LRU cache with basic telemetry.

__init__(max_size=128)[source]
get(key)[source]
set(key, value)[source]
delete(key)[source]
clear()[source]
stats()[source]
items()[source]
class tooluniverse.cache.memory_cache.SingleFlight[source]

Bases: object

Per-key lock manager to collapse duplicate cache misses.

__init__()[source]
acquire(key)[source]

tooluniverse.cache.result_cache_manager module

Result cache manager that coordinates in-memory and persistent storage.

class tooluniverse.cache.result_cache_manager.CacheRecord[source]

Bases: object

CacheRecord(value: ‘Any’, expires_at: ‘Optional[float]’, namespace: ‘str’, version: ‘str’)

value: Any
expires_at: float | None
namespace: str
version: str
__init__(value, expires_at, namespace, version)
class tooluniverse.cache.result_cache_manager.ResultCacheManager[source]

Bases: object

Facade around memory + persistent cache layers.

__init__(*, memory_size=256, persistent_path=None, enabled=True, persistence_enabled=True, singleflight=True, default_ttl=None, async_persist=None, async_queue_size=10000)[source]
static compose_key(namespace, version, cache_key)[source]
get(*, namespace, version, cache_key)[source]
set(*, namespace, version, cache_key, value, ttl=None)[source]
delete(*, namespace, version, cache_key)[source]
clear(namespace=None)[source]
bulk_get(requests)[source]

Fetch multiple cache entries at once.

Parameters:

requests (Sequence[Dict[str, str]]) – Iterable of dicts containing namespace, version and cache_key.

Returns

Mapping of composed cache keys to cached values.

stats()[source]
dump(namespace=None)[source]
singleflight_guard(composed_key)[source]
close()[source]

Close the cache manager and cleanup resources.

__del__()[source]

Ensure cleanup happens even if close() is not called explicitly.

flush()[source]

tooluniverse.cache.sqlite_backend module

SQLite-backed persistent cache for ToolUniverse.

The cache stores serialized tool results with TTL and version metadata. Designed to be a drop-in persistent layer behind the in-memory cache.

class tooluniverse.cache.sqlite_backend.CacheEntry[source]

Bases: object

CacheEntry(key: ‘str’, value: ‘Any’, namespace: ‘str’, version: ‘str’, ttl: ‘Optional[int]’, created_at: ‘float’, last_accessed: ‘float’, hit_count: ‘int’, expires_at: ‘Optional[float]’ = None)

key: str
value: Any
namespace: str
version: str
ttl: int | None
created_at: float
last_accessed: float
hit_count: int
expires_at: float | None = None
__init__(key, value, namespace, version, ttl, created_at, last_accessed, hit_count, expires_at=None)
class tooluniverse.cache.sqlite_backend.PersistentCache[source]

Bases: object

SQLite-backed cache layer with TTL support.

__init__(path, *, enable=True)[source]
close()[source]
cleanup_expired()[source]
get(cache_key)[source]
set(cache_key, value, *, namespace, version, ttl, created_at=None, expires_at=None)[source]
delete(cache_key)[source]
clear(namespace=None)[source]
iter_entries(namespace=None)[source]
stats()[source]