Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.encoreos.io/llms.txt

Use this file to discover all available pages before exploring further.

Status: ✅ Complete
Spec: PF-51 Caching Layer & Strategy

Purpose

Centralized in-memory cache for query results, configuration, and reference data. All keys are tenant-scoped: org-{orgId}:{namespace}:{key}.

Public API

ExportTypeDescription
cacheServiceCacheServiceget, set, delete, clear(pattern), invalidate(pattern)
useCachedQueryhookTanStack Query-backed cache for React
createCacheKeyfunctionBuild full key from orgId, namespace, key
requireOrganizationIdfunctionThrow if missing org
warmCachefunctionWarm cache for an organization (async)
getCacheStatsfunctionHit/miss counts and hit rate (programmatic)
invalidateCacheForUserfunctionInvalidate keys for org-:user-:*
purgeCacheForDeactivatedUserfunctionSame as invalidateCacheForUser

Key format

  • Full key: org-{organizationId}:{namespace}:{key}.
  • Organization ID is required; omit only when using helpers that inject it (e.g. useCachedQuery uses current org from context).
  • Missing org throws: “Cache requires organization context”.

Usage

import { cacheService, createCacheKey, useCachedQuery } from '@/platform/cache';

// With explicit org (e.g. in queryFn)
const key = createCacheKey(orgId, 'my-namespace', 'item-1');
await cacheService.set(key, data, { ttl: 300 });
const value = await cacheService.get(key);

// React: useCachedQuery injects org from useOrganization()
const { data } = useCachedQuery(['my-query'], () => fetchData(), { staleTime: 300000 });

Security

  • No PHI/PII in cache keys or values per policy.
  • Tenant isolation enforced by key format and org validation.
  • Cache is cleared on sign-out (wired in ResponsiveNav).
  • User cache is invalidated on role assignment changes (wired in PermissionService).