memory

class litestar.stores.memory.MemoryStore[源代码]

基类:Store

In memory, atomic, asynchronous key/value store.

__init__() None[源代码]

Initialize MemoryStore

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

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

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

async delete_all() None[源代码]

Delete all stored values.

async delete_expired() None[源代码]

Delete expired items.

Since expired items are normally only cleared on access (i.e. when calling get()), this method should be called in regular intervals to free memory.

async exists(key: str) bool[源代码]

Check if a given key exists.

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.