GitHub

PersistedCache

API reference for PersistedCache.

class PersistedCache[K: AnyPersistable, R = Never, A = Any, E = Any]

Make one with make. get's success and error come from the request's schemas; R is what the lookup needs when require_services_at="lookup"; A and E are what the lookup gives, which must fit the request's schemas (get is a pyright error otherwise).

Attributes

AttributeTypeDescription
in_memoryCache[K, Any, Any, Any]

The in-memory cache in front of the store.

Functions

__init__

__init__(in_memory, store) -> None
ParameterTypeDescription
in_memoryCache[K, Any, Any, Any]
storePersistenceStore
def __init__(self, in_memory: Cache[K, Any, Any, Any], store: PersistenceStore) -> None:
    self._in_memory = in_memory
    self._store = store

get

get[AA, EE, RR, SA, SE](key) -> Effect[AA, EE, RR | R]

The outcome for key: from memory, from the store, or looked up now and stored.

ParameterTypeDescription
keyTypedRequest[AA, EE, RR, K]

Returns Effect[AA, EE, RR | R]

def get[AA, EE, RR, SA, SE](
    self: _LookupTypes[HasPersistableTypes[SA, SE], SA, SE],
    key: TypedRequest[AA, EE, RR, K],
) -> Effect[AA, EE, RR | R]:
    """The outcome for ``key``: from memory, from the store, or looked
    up now and stored."""
    cache = cast("PersistedCache[K, R]", self)
    return cache._in_memory.get(key)  # pyright: ignore[reportArgumentType]

invalidate

invalidate(key) -> Effect[None, PersistenceError]

Forget key in the store and in memory.

ParameterTypeDescription
keyK

Returns Effect[None, PersistenceError]

def invalidate(self, key: K) -> Effect[None, PersistenceError]:
    """Forget ``key`` in the store and in memory."""
    return self._store.remove(key).and_then(self._in_memory.invalidate(key))