Skip to content

MemoryCache

Defined in: packages/ddd-core/persistence/cache/memory.cache.ts:57

In-memory implementation of IVersionedCache maintaining deep detachment parity with database/network caches via JSON cloning on both set() and get().

Implements revision-fenced coordination:

  • Every write and invalidation takes the next value of one cache-wide counter.
  • Retains coordination metadata on payload expiry to prevent ABA stale fills.
  • An absent key reports the absence revision, which advances to the counter whenever an entry is evicted or the cache is cleared, so dropping a key’s metadata never returns it to a revision a reader observed before the drop.

T

new MemoryCache<T>(options?): MemoryCache<T>

Defined in: packages/ddd-core/persistence/cache/memory.cache.ts:66

number

number

MemoryCache<T>

readonly isVersioned: true

Defined in: packages/ddd-core/persistence/cache/memory.cache.ts:58

IVersionedCache.isVersioned

get size(): number

Defined in: packages/ddd-core/persistence/cache/memory.cache.ts:237

Current number of keys in the in-memory cache.

number

clear(): Promise<void>

Defined in: packages/ddd-core/persistence/cache/memory.cache.ts:229

Purges all keys from the in-memory cache. Every revision observed before the purge, including an observed absence, is rejected by a later tryFill.

Promise<void>


delete(key): Promise<void>

Defined in: packages/ddd-core/persistence/cache/memory.cache.ts:221

Removes the value and advances the key’s revision, as invalidate() does.

string

Promise<void>

IVersionedCache.delete


get(key): Promise<T | undefined>

Defined in: packages/ddd-core/persistence/cache/memory.cache.ts:208

Retrieves a cached value, checking TTL and returning a detached clone.

string

Promise<T | undefined>

IVersionedCache.get


invalidate(key): Promise<string>

Defined in: packages/ddd-core/persistence/cache/memory.cache.ts:127

Atomically advances the key revision and removes the value.

string

Promise<string>

IVersionedCache.invalidate


readState(key): Promise<CacheStateEntry<T>>

Defined in: packages/ddd-core/persistence/cache/memory.cache.ts:104

Observes current key state and opaque revision token.

string

Promise<CacheStateEntry<T>>

IVersionedCache.readState


set(key, value, options?): Promise<void>

Defined in: packages/ddd-core/persistence/cache/memory.cache.ts:168

Stores a value in memory, cloning it via JSON round-trip to guarantee detachment. Enforces TTL expiration and optional atomic CAS stale-write protection (isNewer).

string

T

CacheSetOptions

Promise<void>

IVersionedCache.set


tryFill(key, observedRevision, value, options?): Promise<boolean>

Defined in: packages/ddd-core/persistence/cache/memory.cache.ts:145

Atomically checks that current revision matches observedRevision, writes value, and advances revision on match.

string

string

T

CacheFillOptions

Promise<boolean>

IVersionedCache.tryFill