Chats kept in one BackingPersistence store, by id.
Functions#
__init__#
__init__(store) -> None| Parameter | Type | Description |
|---|---|---|
store | BackingPersistenceStore |
def __init__(self, store: BackingPersistenceStore) -> None:
self._store = storeget#
get(chat_id, *, time_to_live=None) -> Effect[Persisted, ChatNotFoundError | PersistenceError]The chat stored under chat_id; its saves keep it for
time_to_live (forever when None).
| Parameter | Type | Description |
|---|---|---|
chat_id | str | |
time_to_live | DurationInput | None = None |
Returns Effect[Persisted, ChatNotFoundError | PersistenceError]
def get(
self, chat_id: str, *, time_to_live: DurationInput | None = None
) -> Effect[Persisted, ChatNotFoundError | PersistenceError]:
"""The chat stored under ``chat_id``; its saves keep it for
``time_to_live`` (forever when ``None``)."""
ttl = None if time_to_live is None else from_input_unsafe(time_to_live)
return self._get(chat_id, ttl).with_span("PersistedChat.get")get_or_create#
get_or_create(chat_id, *, time_to_live=None) -> Effect[Persisted, AiError | PersistenceError]The chat stored under chat_id, or a new empty one stored
there.
| Parameter | Type | Description |
|---|---|---|
chat_id | str | |
time_to_live | DurationInput | None = None |
Returns Effect[Persisted, AiError | PersistenceError]
def get_or_create(
self, chat_id: str, *, time_to_live: DurationInput | None = None
) -> Effect[Persisted, AiError | PersistenceError]:
"""The chat stored under ``chat_id``, or a new empty one stored
there."""
ttl = None if time_to_live is None else from_input_unsafe(time_to_live)
got = self._get(chat_id, ttl).catch_all(
lambda error: (
self._create(chat_id, ttl)
if isinstance(error, ChatNotFoundError)
else fx.fail(error)
)
)
return got.with_span("PersistedChat.getOrCreate")