MemoryStore

class MemoryStore(clock: Clock = Clock.System) : Store

A Store that keeps its items in memory, for tests and for apps that remember only while they run. Safe to share between coroutines and threads.

Parameters

Constructors

Link copied to clipboard
constructor(clock: Clock = Clock.System)

Functions

Link copied to clipboard
open suspend override fun delete(namespace: List<String>, key: String)

Removes the item under key in namespace. Does nothing when there is none.

Link copied to clipboard
open suspend override fun get(namespace: List<String>, key: String): StoreItem?

Returns the item under key in namespace, or null when there is none.

Link copied to clipboard
suspend fun <T> Store.get(namespace: List<String>, key: String, serializer: StateSerializer<T>): T?

Returns the value under key in namespace, read with serializer, or null when there is none.

Link copied to clipboard
open suspend override fun list(namespace: List<String>, limit: Int = DEFAULT_LIMIT): List<StoreItem>

Returns the items of namespace and of the namespaces that start with it, the last changed first, at most limit of them. An empty namespace lists the whole store.

Link copied to clipboard
open suspend override fun put(namespace: List<String>, key: String, value: String)

Keeps value under key in namespace, in place of the value that was there.

Link copied to clipboard
suspend fun <T> Store.put(namespace: List<String>, key: String, value: T, serializer: StateSerializer<T>)

Keeps value under key in namespace, written with serializer.

Link copied to clipboard
open suspend fun search(namespace: List<String>, query: String, limit: Int = DEFAULT_SEARCH_LIMIT): List<StoreItem>

Returns the items of namespace and of the namespaces under it that query is about, the best first, at most limit of them.

Link copied to clipboard
fun Store.within(vararg namespace: String): Store

Returns a view of this store whose namespaces all start with namespace. Give each user a view of their own, store.within("users", userId), so that a graph compiled once serves every user, and nothing in it can read what another user's runs wrote.