betty.cache package¶
Submodules¶
Module contents¶
Provide the Cache API.
- class betty.cache.Cache[source]¶
Bases:
Generic[CacheItemValueContraT]Provide a cache.
Implementations MUST be thread-safe.
- get(cache_item_id: str) AsyncContextManager[betty.cache.CacheItem[betty.cache.CacheItemValueContraT] | None][source]¶
Get the cache item with the given ID.
- Parameters:
cache_item_id (
str)- Return type:
typing.AsyncContextManager[typing.Optional[betty.cache.CacheItem[typing.TypeVar(CacheItemValueContraT, contravariant=True)]]]
- getset(cache_item_id: str, *, wait: bool = True) AsyncContextManager[tuple[betty.cache.CacheItem[betty.cache.CacheItemValueContraT] | None, collections.abc.Callable[[betty.cache.CacheItemValueContraT], collections.abc.Awaitable[None]] | None]][source]¶
Get the cache item with the given ID, and provide a setter to add or update it within the same atomic operation.
If
waitisFalseand no lock can be acquired, returnNone, None. Otherwise return: 0. A cache item if one could be found, or elseNone. 1. An asynchronous setter that takes the cache item’s value as its only argument.- Parameters:
- Return type:
typing.AsyncContextManager[tuple[typing.Optional[betty.cache.CacheItem[typing.TypeVar(CacheItemValueContraT, contravariant=True)]],collections.abc.Callable[[typing.TypeVar(CacheItemValueContraT, contravariant=True)],collections.abc.Awaitable[None]] |None]]