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. IfkeyFnreturnsnull, 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
hydrateFnapplies, 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 byserializeFn) 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.
Type Parameters
Section titled “Type Parameters”TQuery
Section titled “TQuery”TQuery extends IQueryOptions = IQueryOptions
TResult
Section titled “TResult”TResult = unknown
Parameters
Section titled “Parameters”keyFnOrOptions
Section titled “keyFnOrOptions”FromCacheOptions<TQuery, TResult> | ((query) => string | null)
hydrateFnOrOptions?
Section titled “hydrateFnOrOptions?”FromCacheOptions<TQuery, TResult> | ((cached) => TResult)
extraOptions?
Section titled “extraOptions?”FromCacheOptions<TQuery, TResult>
Returns
Section titled “Returns”MethodDecorator