Skip to content

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.

T = Record<string, unknown>

string

Key template containing required {prop} or optional {prop?} placeholders.

TenantSource

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.

A key factory accepting either a request object or a CacheKeyRequestContext (such as a request or job context).

(source) => string

When tenant identity cannot be resolved.

When a required placeholder is absent.

const byId = cacheKeyTemplate<{ userId: string }>('user:{userId}');
const key = byId({ userId: '019...' });
// tenant-a:user:019...