@xemahq/grant-cache
v0.1.3
Published
L1 in-process LRU+TTL cache for authorization-api.policyCheck results (Xema OS plan v4.3 §6 Phase E.3). Lives in front of the AuthorizationClient inside `xema-capability-router`; removes ~80% of authorization-api round-trips in a single-replica dev. The L
Readme
@xemahq/grant-cache
In-process TTL cache for policy decisions
Overview
A small, in-process LRU + TTL cache that sits in front of a policy check and remembers each decision keyed by its execution context. On a miss or expiry it calls a caller-supplied filler, and it coalesces concurrent requests for the same key onto a single in-flight call so a burst of identical checks hits the backend once. It also exposes predicate-based invalidation so callers can evict entries when grants change. No network or persistence — one cache instance per process.
When to use it
- Use it to cut repeated round-trips to a policy backend for the same execution context within a single process.
Installation
pnpm add @xemahq/grant-cacheUsage
import { GrantCache } from '@xemahq/grant-cache';
const cache = new GrantCache({
filler: (ctx) => checkPolicy(ctx), // called on miss / expiry
});
const decision = await cache.check(executionContext);License
Apache-2.0 © Xema — xema.dev
