base

members:

Store, NamespacedStore

class litestar.stores.base.NamespacedStore[原始碼]

基底類別: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.

abstractmethod 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[原始碼]

基底類別: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()

class litestar.stores.base.Store[原始碼]

基底類別:ABC

Thread and process safe asynchronous key/value store.

abstractmethod async set(key: str, value: str | bytes, expires_in: int | timedelta | None = None) None[原始碼]

Set a value.

參數:
  • key -- Key to associate the value with

  • value -- Value to store

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

回傳:

None

abstractmethod async get(key: str, renew_for: int | timedelta | None = None) bytes | None[原始碼]

Get a value.

參數:
  • 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

回傳:

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

abstractmethod async delete(key: str) None[原始碼]

Delete a value.

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

參數:

key -- Key of the value to delete

abstractmethod async delete_all() None[原始碼]

Delete all stored values.

abstractmethod async exists(key: str) bool[原始碼]

Check if a given key exists.

abstractmethod 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.