API Reference

Caches

class cachetout.Cache(name: str, app_name: str | None = None, backend: Backend | None = None)

A persistent cache that stores values in a named backend.

get(key: K, *, type: type[V]) → V
get(key: K, *, type: type[V], default: V) → V

Return the value for the given key, decoded as type.

If the key is missing and default is given, return default; otherwise raise KeyError.

set(key: K, value: V, *, expires_at: datetime | None = None) → None

Store the given value against the given key.

If expires_at is given, the value can no longer be retrieved after that time.

Functions

cachetout.cache(*args, **kwargs)

Cache a function’s return values.

Can be used bare (@cache) or with arguments (@cache(name=…), app_name=…, backend=…, expires_in=…). Values are looked up by the function’s arguments and decoded as the function’s return annotation.

Backends

class cachetout.backends.abc.Backend

A storage backend that maps encoded keys to encoded values.

abstractmethod __contains__(key: bytes) → bool

Return whether the backend contains the given key.

abstractmethod __delitem__(key: bytes) → None

Remove the given key from the backend.

abstractmethod __getitem__(key: bytes) → bytes

Return the value for the given key.

Raises KeyError if the key is missing or expired.

abstractmethod __setitem__(key: bytes, value: Value) → None

Store the given value against the given key.