cache

Lightweight on-disk cache for API responses with TTL support.

class drugs.cache.APICache(path: Path = PosixPath('artifacts/cache/api_cache.json'), *, default_ttl: float = 86400.0, enabled: bool = True)

Bases: object

Simple JSON-backed cache with expiration timestamps.

The cache is intentionally lightweight and avoids external dependencies. Entries are stored as {"value": obj, "expires_at": epoch_seconds}.

clear_expired() None
get(key: str) Any | None
set(key: str, value: Any, *, ttl: float | None = None) None
invalidate(key: str | None = None) None
drugs.cache.get_default_cache() APICache | None

Return a process-wide default API cache instance.