Skip to content

cacheKey

cacheKey(resourceOrEntity, conditions, tenantOrContext?): string

Defined in: packages/ddd-core/persistence/helpers/cache-key.helper.ts:89

Derives a deterministic, collision-safe cache key from a canonical structured tuple [tenant, resource, normalizedFilter], versioned and hashed with SHA-256.

Guarantees:

  • Deterministic ordering: object keys are sorted recursively.
  • Type preservation: numbers, booleans, strings, and nulls produce distinct representations.
  • Null retention: explicit null conditions are preserved, distinct from omitted/undefined keys.
  • Fail-safe boundaries: non-serializable types and cyclic structures are rejected.
  • Versioned namespace: keys are namespaced as ${tenant}:${resource}:v1:${hash}.

CacheResourceSpecifier

Logical resource name or object exposing aggregateName.

Record<string, unknown>

Filter values that identify the cached record/query.

TenantSource

An explicit tenant id, or an object carrying tenantId (such as a request or job context). When omitted, the tenant of the registered setTenantResolver resolver is used. See CacheKeyTenantSource.

string

A versioned, hashed deterministic cache key.

When tenant identity cannot be resolved.

When conditions contain non-serializable values.