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.

async clear()[source]

Clear all items from the cache.

Return type:

None

async delete(cache_item_id)[source]

Delete the cache item with the given ID.

Parameters:
cache_item_id

Return type:

None

get(cache_item_id)[source]

Get the cache item with the given ID.

Parameters:
cache_item_id

Return type:

typing.AsyncContextManager[typing.Optional[betty.cache.CacheItem[typing.TypeVar(CacheItemValueContraT, contravariant=True)]]]

getset(cache_item_id, *, wait=True)[source]

Get the cache item with the given ID, and provide a setter to add or update it within the same atomic operation.

If wait is False and no lock can be acquired, return None, None. Otherwise return: 0. A cache item if one could be found, or else None. 1. An asynchronous setter that takes the cache item’s value as its only argument.

Parameters:
cache_item_id

wait=True

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]]

async set(cache_item_id, value, *, modified=None)[source]

Add or update a cache item.

Parameters:
cache_item_id

value

modified=None

Return type:

None

with_scope(scope)[source]

Return a new nested cache with the given scope.

Parameters:
scope

Return type:

typing.Self

class betty.cache.CacheItem[source]

Bases: Generic[CacheItemValueCoT]

property modified : int | float

Get the time this cache item was last modified, in seconds.

async value()[source]

Get this cache item’s value.

Return type:

typing.TypeVar(CacheItemValueCoT, covariant=True)

class betty.cache.FileCache(**kwargs)[source]

Bases: object

async clear()[source]
Return type:

None

property path : Path