MemoryStorageV2 class

An in-memory provider for the structured StorageV2 contract.

Unlike MemoryStorage, every read returns an outcome for every requested key, and every write and delete returns an outcome for every supplied key. Storage versions are returned separately from application values, so an eTag property in a value is preserved. Use StorageWriteMode.CreateOnly, StorageWriteMode.Replace, or expectedVersion to guard concurrent writes.

This provider is intended for development and testing only; state is process-local.

Extends

Constructors

MemoryStorageV2({[key: string]: string})

Creates a V2 in-memory storage provider.

Methods

delete(string[], StorageDeleteOptions)

Deletes items from process-local memory with an optional version condition.

getSingleInstance()
read<T>(string[])

Reads items from process-local memory.

write<T>(Record<string, T>, StorageWriteOptions)

Writes items to process-local memory with optional concurrency conditions.

Constructor Details

MemoryStorageV2({[key: string]: string})

Creates a V2 in-memory storage provider.

new MemoryStorageV2(memory?: {[key: string]: string})

Parameters

memory

{[key: string]: string}

Optional backing store to share with another in-memory storage instance.

Method Details

delete(string[], StorageDeleteOptions)

Deletes items from process-local memory with an optional version condition.

function delete(keys: string[], options?: StorageDeleteOptions): Promise<StorageDeleteResults>

Parameters

keys

string[]

The keys to delete. Empty batches are valid.

options
StorageDeleteOptions

An optional expected storage version.

Returns

A result for every supplied key.

getSingleInstance()

static function getSingleInstance(): MemoryStorageV2

Returns

read<T>(string[])

Reads items from process-local memory.

function read<T>(keys: string[]): Promise<StorageReadResults<T>>

Parameters

keys

string[]

The keys to read. Empty batches are valid.

Returns

Promise<StorageReadResults<T>>

A result for every key, with notFound for missing items and a separate storage version for successful reads.

write<T>(Record<string, T>, StorageWriteOptions)

Writes items to process-local memory with optional concurrency conditions.

function write<T>(changes: Record<string, T>, options?: StorageWriteOptions): Promise<StorageWriteResults>

Parameters

changes

Record<string, T>

The values to write, keyed by storage key.

options
StorageWriteOptions

Create-only, replace, or expected-version conditions.

Returns

A result for every supplied key, including conflict or conditionNotMet when a condition cannot be satisfied.