Class: MemoryStore<K, V> ​
Defined in: store.ts:73
Re-implementation of a simple in-memory key-value store.
The MemoryStore class is an implementation of KeyValueStore that holds data in memory.
It provides a basic key-value store that works synchronously and keeps all data in memory. This can be used for testing, or for handling small amounts of data with simple key-value semantics.
Example usage:
const memoryStore = new MemoryStore<string, number>();
await memoryStore.set("key1", 1);
const value = await memoryStore.get("key1");
console.log(value); // 1Type Parameters ​
K ​
K
V ​
V
Implements ​
KeyValueStore<K,V>
Constructors ​
Constructor ​
new MemoryStore<
K,V>():MemoryStore<K,V>
Returns ​
MemoryStore<K, V>
Methods ​
clear() ​
clear():
void
Defined in: store.ts:84
Clears all entries in the key-value store.
Returns ​
void
returns once the operation is complete.
Implementation of ​
close() ​
close():
void
Defined in: store.ts:91
This operation is no-op for MemoryStore.
Returns ​
void
Implementation of ​
delete() ​
delete(
id):boolean
Defined in: store.ts:101
Deletes an entry from the key-value store by its key.
Parameters ​
id ​
K
The key of the entry to delete.
Returns ​
boolean
a boolean indicating whether the entry was successfully deleted.
Implementation of ​
entries() ​
entries(): [
K,V][]
Defined in: store.ts:139
Retrieves all entries in the key-value store.
Returns ​
[K, V][]
an array of key-value pairs in the store.
Implementation of ​
get() ​
get(
id):V|undefined
Defined in: store.ts:111
Retrieves the value of an entry by its key.
Parameters ​
id ​
K
The key of the entry to retrieve.
Returns ​
V | undefined
the value of the entry, or undefined if the entry does not exist.
Implementation of ​
has() ​
has(
id):boolean
Defined in: store.ts:121
Checks for the presence of an entry by key.
Parameters ​
id ​
K
The key to check for the existence of.
Returns ​
boolean
a boolean indicating whether an element with the specified key exists or not.
list() ​
list():
V[]
Defined in: store.ts:130
Retrieves all values in the key-value store.
Returns ​
V[]
an array of all values in the store.
set() ​
set(
id,key):void
Defined in: store.ts:150
Sets the value of an entry in the key-value store.
Parameters ​
id ​
K
The key of the entry to set.
key ​
V
The new value for the entry.
Returns ​
void
once operation is complete.