LogoRobo.js
Framework

MemoryAdapter<K, V>

Class: MemoryAdapter<K, V>

In-memory storage adapter using Map.

Implements all optional capabilities:

  • scan: prefix-based key listing
  • setIfNotExists: atomic conditional set
  • compareAndSwap: atomic update with version check
  • atomicBatch: atomic multi-key operations

Useful for:

  • Unit testing
  • Development without external dependencies
  • Ephemeral data that doesn't need persistence

Type Parameters

Type ParameterDefault type
K extends stringstring
Vunknown

Implements

Constructors

new MemoryAdapter()

new MemoryAdapter<K, V>(): MemoryAdapter<K, V>

Returns

MemoryAdapter<K, V>

Properties

PropertyModifierTypeDefault valueDescription
namereadonly"MemoryAdapter"'MemoryAdapter'Human-readable adapter name for logging and introspection.

Methods

atomicBatch()

atomicBatch(ops): void

Apply a batch of operations atomically.

In memory, this is trivially atomic since JavaScript is single-threaded. Validates check operations before applying any changes.

Parameters

ParameterType
opsBatchOperation<K, V>[]

Returns

void

Implementation of

FlashcoreAdapter.atomicBatch


capabilities()

capabilities(): AdapterCapabilitiesReport

Report extended capabilities.

Returns

AdapterCapabilitiesReport

Implementation of

FlashcoreAdapter.capabilities


clear()

clear(): void

Clear all data.

Returns

void

Implementation of

FlashcoreAdapter.clear


compareAndSwap()

compareAndSwap(
   key, 
   expected, 
   next): boolean

Compare and swap: update only if current value equals expected.

Uses JSON serialization for deep equality check. Returns true if swap succeeded, false if value differs.

Parameters

ParameterType
keyK
expectedV
nextV

Returns

boolean

Implementation of

FlashcoreAdapter.compareAndSwap


delete()

delete(key): boolean

Delete a key. Returns true if the key existed and was deleted.

Parameters

ParameterType
keyK

Returns

boolean

Implementation of

FlashcoreAdapter.delete


entries()

entries(): [K, V][]

Get all entries (for testing/debugging).

Returns

[K, V][]


get()

get(key): V

Get a value by key. Returns undefined if the key does not exist.

Parameters

ParameterType
keyK

Returns

V

Implementation of

FlashcoreAdapter.get


has()

has(key): boolean

Check if a key exists. Must return true for stored falsy values (0, false, '', null).

Parameters

ParameterType
keyK

Returns

boolean

Implementation of

FlashcoreAdapter.has


init()

init(): void

Initialize the adapter (e.g., connect, create directories). Called once during Flashcore.$.init().

Returns

void

Implementation of

FlashcoreAdapter.init


keys()

keys(): K[]

Get all keys (for testing/debugging).

Returns

K[]


restore()

restore(snapshot): void

Restore from a snapshot (for testing).

Parameters

ParameterType
snapshotMap<K, V>

Returns

void


scan()

scan(prefix): K[]

Scan for keys with a given prefix. Returns an array for simplicity (small keysets in testing).

Parameters

ParameterType
prefixK

Returns

K[]

Implementation of

FlashcoreAdapter.scan


set()

set(key, value): boolean

Set a key-value pair. Returns true if the operation succeeded.

Parameters

ParameterType
keyK
valueV

Returns

boolean

Implementation of

FlashcoreAdapter.set


setIfNotExists()

setIfNotExists(key, value): boolean

Set a key only if it doesn't exist. Returns true if set, false if key already exists.

Parameters

ParameterType
keyK
valueV

Returns

boolean

Implementation of

FlashcoreAdapter.setIfNotExists


shutdown()

shutdown(): void

Shutdown the adapter (e.g., close connections).

Returns

void

Implementation of

FlashcoreAdapter.shutdown


size()

size(): number

Get the number of stored keys.

Returns

number


snapshot()

snapshot(): Map<K, V>

Get a snapshot of the storage (for testing).

Returns

Map<K, V>

On this page