cacheKeyTemplate
cacheKeyTemplate<
T>(template,tenantOrContext?): (source) =>string
Defined in: packages/ddd-core/persistence/helpers/cache-key.helper.ts:160
Resolves a template string (e.g. user:{userId}) against a query/command payload,
namespaced by the active tenant schema.
Required placeholders throw when absent; optional {prop?} placeholders resolve
to an empty string. Object placeholder values use the same canonical serializer
as cacheKey.
Type Parameters
Section titled “Type Parameters”T = Record<string, unknown>
Parameters
Section titled “Parameters”template
Section titled “template”string
Key template containing required {prop} or optional {prop?} placeholders.
tenantOrContext?
Section titled “tenantOrContext?”An explicit tenant used to namespace produced keys. When
omitted, a context source’s tenantId is used, and otherwise the tenant of the
registered setTenantResolver resolver.
Returns
Section titled “Returns”A key factory accepting either a request object or a CacheKeyRequestContext (such as a request or job context).
(source) => string
Throws
Section titled “Throws”When tenant identity cannot be resolved.
Throws
Section titled “Throws”When a required placeholder is absent.
Example
Section titled “Example”const byId = cacheKeyTemplate<{ userId: string }>('user:{userId}');const key = byId({ userId: '019...' });// tenant-a:user:019...