LocalStorageStore

class LocalStorageStore(keyPrefix: String = "telar.store.", clock: Clock = Clock.System) : Store

A persistent Store for apps that run in a browser. It keeps each item in an entry of the page's localStorage, so what an agent remembers is still there after the page is reloaded or the browser is closed.

val config = GraphConfig(
threadId = "plan-7",
checkpointer = LocalStorageCheckpointer(KotlinxStateSerializer<Trip>()),
store = LocalStorageStore().within("traveller"),
)

What LocalStorageCheckpointer says about localStorage holds here too: it belongs to the origin of the page, so give keyPrefix a name of your own; a browser keeps about 5 MB for an origin, and a put into a full storage throws a LocalStorageStoreException and leaves the items as they were; the person using the browser can read and change it; and it is not available in a web worker, on Node.js, or when the browser blocks storage for the page.

The key of an entry is keyPrefix, then each part of the namespace followed by /, then the key, with % and / in a part or the key written as %25 and %2F. Its value is JSON with the value of the item and its time. list reads the keys of every entry of the page, which is quick for the size localStorage has.

Parameters

keyPrefix

what the key of an entry starts with. It must not be the start of the keyPrefix of a checkpointer or another store of the page, so that list finds only its own.

clock

gives StoreItem.updatedAt. Two writes of one store never get the same time, and a store starts after the last write it finds, so list keeps their order also with the clock of a browser, which counts milliseconds.

Constructors

Link copied to clipboard
constructor(keyPrefix: String = "telar.store.", clock: Clock = Clock.System)

Functions

Link copied to clipboard
open suspend override fun delete(namespace: List<String>, key: String)
Link copied to clipboard
open suspend override fun get(namespace: List<String>, key: String): StoreItem?
Link copied to clipboard
open suspend override fun list(namespace: List<String>, limit: Int): List<StoreItem>
Link copied to clipboard
open suspend override fun put(namespace: List<String>, key: String, value: String)
Link copied to clipboard
open suspend fun search(namespace: List<String>, query: String, limit: Int): List<StoreItem>