MemoryStateStore

State store that keeps states in the process memory.

Implements: IReconfigurable, IStateStore

Description

Remember: This implementation is not suitable for synchronization of distributed processes.

Configuration parameters

options:

  • timeout: default caching timeout in milliseconds (default: disabled)

Instance methods

configure

Configures component by passing configuration parameters.

public configure(config: ConfigParams): void

  • config: ConfigParams - configuration parameters to be set.

delete

Deletes a state from the store by its key.

public delete<T>(correlationId: string, key: string): Promise<T>

  • correlationId: string - (optional) transaction id to trace execution through a call chain.
  • key: string - a unique value key.
  • return: Promise<T> - removed item

load

Loads state from the store using its key. If value is missing in the store it returns null.

public load<T>(correlationId: string, key: string): Promise<T>

  • correlationId: string - (optional) transaction id to trace execution through a call chain.
  • key: string - a unique state key.
  • return: Promise<T> - the state value or null if value wasn’t found.

loadBulk

Loads an array of states from the store using their keys.

public loadBulk<T>(correlationId: string, keys: string[]): Promise<StateValue<T>[]>

  • correlationId: string - (optional) transaction id to trace execution through call chain.
  • keys: string[] - unique state keys.
  • returns: Promise<StateValue<T>[]> - an array with state values and their corresponding keys.

save

Saves state into the store.

public save<T>(correlationId: string, key: string, value: any): Promise<T>

  • correlationId: string - (optional) transaction id to trace execution through a call chain.
  • key: string - a unique state key.
  • value: any - a state value.
  • returns: Promise<T> - execution duration in milliseconds.

Examples

let store = new MemoryStateStore();

let value = await store.load("123", "key1");
...
await store.save("123", "key1", "ABC");

See also