Skip to main content

Caches.get()

The named plain cache as caches[name] returns it, or default if no cache by that name

Usage

Source

Caches.get(self, name: str) -> Optional[TransactionalCacheLike]
 
Caches.get(self, name: str, default: D) -> TransactionalCacheLike | D

is registered. One call instead of name in caches and then caches[name].

default is for a name that was never registered, nothing else: a registered cache that can’t open or is disabled still comes back as a NullCache, as from caches[name]. name is typed str even on a Caches[Literal[...]], since asking about a name that may not be there is the point.

Raises

TypeError

The cache was registered with shards= (use fanout(name)), or its settings are invalid.

ValueError
Its settings are invalid.

Examples

if (pages := caches.get('pages')) is None:
    raise RuntimeError('the pages cache was not registered')
pages.set('/about', html)