Skip to content

MikroOrmCache

Defined in: packages/ddd-mikro-orm/src/cache/mikro-orm.cache.ts:90

MikroORM-backed IVersionedCache: one row per key in the table mapped by CacheEntrySchema (or createCacheEntrySchema).

Implements IVersionedCache with revision-fenced atomic coordination, bypassing the identity map across all read and mutation operations. Reads use store.em; every write runs in store.transactional(...).

A plain class with no framework dependency. In a NestJS application, register it with a factory:

{
provide: CACHE_TOKEN,
useFactory: (store: AppStore) =>
new MikroOrmCache(store, { logger: new Logger('MikroOrmCache') }),
inject: [STORE],
}

T

new MikroOrmCache<T>(store, options?): MikroOrmCache<T>

Defined in: packages/ddd-mikro-orm/src/cache/mikro-orm.cache.ts:96

ITransactionalEntityManagerSource

MikroOrmCacheOptions

MikroOrmCache<T>

readonly isVersioned: true

Defined in: packages/ddd-mikro-orm/src/cache/mikro-orm.cache.ts:91

IVersionedCache.isVersioned

delete(key): Promise<void>

Defined in: packages/ddd-mikro-orm/src/cache/mikro-orm.cache.ts:314

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

string

Promise<void>

IVersionedCache.delete


get(key): Promise<T | undefined>

Defined in: packages/ddd-mikro-orm/src/cache/mikro-orm.cache.ts:246

Get a value from the cache by key. Handles TTL expiry and returns detached clone.

string

Promise<T | undefined>

IVersionedCache.get


invalidate(key): Promise<string>

Defined in: packages/ddd-mikro-orm/src/cache/mikro-orm.cache.ts:140

Atomically advances the revision for key and evicts the payload value. Retains the entry to prevent ABA races during concurrent fills.

string

Promise<string>

IVersionedCache.invalidate


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

Defined in: packages/ddd-mikro-orm/src/cache/mikro-orm.cache.ts:108

Observes the current key state and its revision token. Reads bypass the identity map to guarantee authoritative persistence visibility.

string

Promise<CacheStateEntry<T>>

IVersionedCache.readState


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

Defined in: packages/ddd-mikro-orm/src/cache/mikro-orm.cache.ts:254

Stores a value in the relational cache table with transactional CAS concurrency safety.

string

T

CacheSetOptions

Promise<void>

IVersionedCache.set


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

Defined in: packages/ddd-mikro-orm/src/cache/mikro-orm.cache.ts:185

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

string

string

T

CacheFillOptions

Promise<boolean>

IVersionedCache.tryFill