MemoryStorage class

A simple in-memory storage provider for development and testing.

This class implements the legacy Storage contract. Use MemoryStorageV2 for the structured StorageV2 contract.

Extends

MemoryStorageInternals

Constructors

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

Creates a legacy in-memory storage provider.

Inherited Properties

state

The shared values and metadata for this storage instance.

Methods

delete(string[])

Deletes legacy items from process-local memory.

getSingleInstance()

Returns the process-wide legacy memory storage instance.

read(string[])

Reads legacy items from process-local memory.

write(StoreItem)

Writes legacy items to process-local memory.

Inherited Methods

getVersion(string, StoreItem)

Gets the version associated with a stored value.

isExpired(string)

Determines whether a stored value has expired.

remove(string)

Removes a value and its version and expiration metadata.

save(string, unknown, number)

Saves a value and updates its version and expiration metadata.

Constructor Details

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

Creates a legacy in-memory storage provider.

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

Parameters

memory

{[key: string]: string}

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

Inherited Property Details

state

The shared values and metadata for this storage instance.

state: MemoryStorageState

Property Value

MemoryStorageState

Inherited From MemoryStorageInternals.state

Method Details

delete(string[])

Deletes legacy items from process-local memory.

function delete(keys: string[]): Promise<void>

Parameters

keys

string[]

The keys to delete. Missing keys are ignored.

Returns

Promise<void>

getSingleInstance()

Returns the process-wide legacy memory storage instance.

static function getSingleInstance(): MemoryStorage

Returns

read(string[])

Reads legacy items from process-local memory.

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

Parameters

keys

string[]

The keys to read; must not be empty.

Returns

Promise<StoreItem>

Existing items keyed by storage key. Missing keys are omitted and returned items include their legacy eTag.

write(StoreItem)

Writes legacy items to process-local memory.

function write(changes: StoreItem): Promise<void>

Parameters

changes
StoreItem

The items to write, keyed by storage key.

Returns

Promise<void>

Inherited Method Details

getVersion(string, StoreItem)

Gets the version associated with a stored value.

function getVersion(key: string, value: StoreItem): string | undefined

Parameters

key

string

The storage key.

value
StoreItem

The stored value.

Returns

string | undefined

The version, when available.

Inherited From MemoryStorageInternals.getVersion

isExpired(string)

Determines whether a stored value has expired.

function isExpired(key: string): boolean

Parameters

key

string

The storage key.

Returns

boolean

true when the value has expired; otherwise, false.

Inherited From MemoryStorageInternals.isExpired

remove(string)

Removes a value and its version and expiration metadata.

function remove(key: string)

Parameters

key

string

The storage key.

Inherited From MemoryStorageInternals.remove

save(string, unknown, number)

Saves a value and updates its version and expiration metadata.

function save(key: string, item: unknown, expiresAt?: number): string

Parameters

key

string

The storage key.

item

unknown

The value to store.

expiresAt

number

The optional expiration time, expressed as Unix time in milliseconds.

Returns

string

The new version.

Inherited From MemoryStorageInternals.save