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#
| Attribute | Type | Description |
|---|---|---|
in_memory | Cache[K, Any, Any, Any] | The in-memory cache in front of the store. |
Functions#
__init__#
__init__(in_memory, store) -> None| Parameter | Type | Description |
|---|---|---|
in_memory | Cache[K, Any, Any, Any] | |
store | PersistenceStore |
def __init__(self, in_memory: Cache[K, Any, Any, Any], store: PersistenceStore) -> None:
self._in_memory = in_memory
self._store = storeget#
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.
| Parameter | Type | Description |
|---|---|---|
key | TypedRequest[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.
| Parameter | Type | Description |
|---|---|---|
key | K |
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))