base#

members:

Store, NamespacedStore

class litestar.stores.base.Store#

Bases: ABC

Thread and process safe asynchronous key/value store.

abstract async set(key: str, value: str | bytes, expires_in: int | timedelta | None = None) None#

Set a value.

Parameters:
  • key – Key to associate the value with

  • value – Value to store

  • expires_in – Time in seconds before the key is considered expired

Returns:

None

abstract async get(key: str, renew_for: int | timedelta | None = None) bytes | None#

Get a value.

Parameters:
  • key – Key associated with the value

  • renew_for – If given and the value had an initial expiry time set, renew the expiry time for renew_for seconds. If the value has not been set with an expiry time this is a no-op

Returns:

The value associated with key if it exists and is not expired, else None

abstract async delete(key: str) None#

Delete a value.

If no such key exists, this is a no-op.

Parameters:

key – Key of the value to delete

abstract async delete_all() None#

Delete all stored values.

abstract async exists(key: str) bool#

Check if a given key exists.

abstract async expires_in(key: str) int | None#

Get the time in seconds key expires in. If no such key exists or no expiry time was set, return None.

class litestar.stores.base.NamespacedStore#

Bases: Store

A subclass of Store, offering hierarchical namespacing.

Bulk actions on a parent namespace should affect all child namespaces, whereas other operations on all namespaces should be isolated.

abstract with_namespace(namespace: str) Self#

Return a new instance of NamespacedStore, which exists in a child namespace of the current namespace. Bulk actions on the parent namespace should affect all child namespaces, whereas other operations on all namespaces should be isolated.

class litestar.stores.base.StorageObject#

Bases: Struct

msgspec.Struct to store serialized data alongside with their expiry time.

classmethod new(data: bytes, expires_in: int | timedelta | None) StorageObject#

Construct a new StorageObject instance.

property expired: bool#

Return if the StorageObject is expired

property expires_in: int#

Return the expiry time of this StorageObject in seconds. If no expiry time was set, return -1.

to_bytes() bytes#

Encode the instance to bytes

classmethod from_bytes(raw: bytes) StorageObject#

Load a previously encoded with StorageObject.to_bytes()