Skip to content

Cache

Pluggable cache backends for LLM classification and extraction results.

CacheBackend Protocol

CacheBackend

Bases: Protocol

Minimal key-value cache protocol. Implement this to bring your own backend.

get

get(key)

Return the stored JSON string for key, or None on miss.

put

put(key, value)

Store a JSON string under key.

delete

delete(key)

Remove a single key.

clear

clear()

Remove all entries.

keys

keys()

Return all stored keys.

close

close()

Release any resources (connections, file handles).

InMemoryCache

LRU-bounded in-memory cache. Default maxsize=10,000 entries. When full, the least recently accessed entry is evicted.

InMemoryCache

InMemoryCache(maxsize=10000)

Default cache — LRU-bounded OrderedDict, zero disk I/O.

maxsize limits the number of entries. When the limit is reached the least-recently-used entry is evicted. Pass 0 to disable the limit.

SQLiteCache

SQLiteCache

SQLiteCache(cache_dir)

Opt-in persistent cache backed by SQLite. WAL mode for concurrent safety.

Usage

cache = SQLiteCache("~/.pygaeb/cache") # directory path cache = SQLiteCache("/tmp/my-cache")