betty.caches.memory module

Provide caching that stores cache items in volatile memory.

final class betty.caches.memory.MemoryCache

Bases: _CommonCacheBase, Generic

Provide a cache that stores cache items in volatile memory.

__init__(*, scopes: Sequence[str] = (), state: _MemoryCacheState | None = None)
async clear() None

Clear all items from the cache.

This operation s unsafe and MAY cause other concurrent operations on this cache to fail.

async delete(cache_item_id: str, /) None

Delete the cache item with the given ID.

This operation s unsafe and MAY cause other concurrent operations on this cache to fail.

async get(cache_item_id: str, /) CacheItem[CacheItemValueT] | None

Get the cache item with the given ID.

async set(cache_item_id: str, value: CacheItemValueT, *, modified: float | None = None) None

Add or update a cache item.

with_scope(scope: str, /) Self

Return a new nested cache with the given scope.