Skip to content

createPartitionedCacheKeyFactory

createPartitionedCacheKeyFactory(options): CacheKeyFactory

Defined in: packages/pipeline-cache/src/helpers/cache-key.ts:102

Builds a cache key that partitions every dimension capable of changing an authorized response.

The key includes tenant, principal, optional permission scope, request type, and a SHA-256 digest of the request payload. This keeps raw request data out of cache key listings while preventing authorized responses from being shared across callers with different security context.

Use this helper when a cache hit can bypass authorization or response filtering performed inside the handler.

PartitionedCacheKeyOptions

Resolvers and fail-closed requirements for key partitioning.

CacheKeyFactory

A CacheKeyFactory suitable for CacheBehaviorOptions.key.

When requireScope is not false and no scope resolver is given.

(from the returned factory) When a required tenant, principal or scope is absent.

Per principal, tenant-aware, invalidated when roles change

class GetUsersHandler {
@pipeline.wrap({ kind: 'query' }, [CacheBehavior, {
key: createPartitionedCacheKeyFactory({
principal: (ctx) => ctx.items.get('currentUserId') as string | undefined,
scope: (ctx) => ctx.items.get('capabilityVersion') as string | undefined,
}),
}])
async handle(query: GetUsersQuery) {}
}

Public reference data, identical for every caller

createPartitionedCacheKeyFactory({
principal: () => 'public',
requirePrincipal: false,
requireTenant: false,
requireScope: false,
});