Skip to content

FromCache

FromCache<TQuery, TResult>(keyFnOrOptions, hydrateFnOrOptions?, extraOptions?): MethodDecorator

Defined in: packages/ddd-core/persistence/decorators/from-cache.decorator.ts:135

Read-through cache decorator for a QueryRepository find method.

Provides declarative read-through caching with revision-fenced coordination:

  • Key derivation: Generates a cache key via keyFn. If keyFn returns null, caching is skipped.
  • Snapshot storage contract: Stores strictly serializable snapshots in the cache, never live domain aggregates.
  • Consistent result shape: When a method or repository hydrateFn applies, every hit is rehydrated, so hits and misses return the same type. Without a hydrator only plain-data results are cached; any other result (a class instance, or a result reshaped by serializeFn) is returned uncached and reported once.
  • Revision-fenced consistency: When coordinated via IVersionedCache, cache fill attempts verify the observed revision token atomically (tryFill). A fill started before an observed invalidation cannot repopulate the key afterwards.
  • Bounded retry: Contended fills inspect current cache state and boundedly retry authoritative reads before falling back to un-cached database results.

TQuery extends IQueryOptions = IQueryOptions

TResult = unknown

FromCacheOptions<TQuery, TResult> | ((query) => string | null)

FromCacheOptions<TQuery, TResult> | ((cached) => TResult)

FromCacheOptions<TQuery, TResult>

MethodDecorator