Skip to content

feat(cache): household membership cache (closes #2264) - #2323

Merged
github-actions[bot] merged 1 commit into
Smartdevs17:mainfrom
IVANLI2412:fix/issue-2264-household-cache
Nov 24, 2026
Merged

github-actions[bot] merged 1 commit into
Smartdevs17:mainfrom
IVANLI2412:fix/issue-2264-household-cache

Conversation

@IVANLI2412

Copy link
Copy Markdown
Contributor

Closes #2264

Summary

Adds a household-membership cache for the request middleware, implemented as two new zero-dependency TypeScript modules plus unit tests. Both target files were missing upstream and are created fresh; no unrelated files are touched.

  • backend/src/lib/cache.ts — pure TTL + LRU cache: typed error surface with stable codes (CacheError/CacheErrorCode), validated config factory (validateCacheConfig, frozen DEFAULT_CACHE_CONFIG with injectable clock), noop metrics/logger hooks, and createTtlCache<T>() returning a frozen handle with get/set/delete/clear/has/size/entries/keys/invalidateByPrefix/prune/stats. Lazy TTL expiry on access, eager pruning, bounded LRU eviction with recency refresh on reads, per-entry TTL overrides, frozen snapshots and internal counters.
  • backend/src/middleware/householdLoader.ts — membership loader built on the injected cache: typed HouseholdLoaderError/HouseholdLoaderErrorCode, validated config factory, deterministic collision-free keying by household and user (percent-encoded components), caching of both positive and negative lookups, load(userId, householdId), invalidate(...), invalidateUser(...) (all households for a user via prefix), invalidateAll(), and metrics/logger hooks. Source resolver is injected; no runtime imports, no I/O performed by the module.
  • Tests — cache.test.ts (20 assertions) and householdLoader.test.ts (24 assertions) cover happy path, injectable-clock TTL expiry, stale entries, LRU eviction, per-entry TTL, all invalidation scopes, source failures, malformed input, dependency validation, counters and observability hooks.

Design follows the existing backend/src/lib engine style: pure functions, typed errors with stable codes, config factory, factory function, and optional metrics/logger hooks. No new dependencies, no binaries, no new markdown/JSON docs (documentation is JSDoc in source).

Verification

  • Node 26 native type-stripping harness importing the real .ts sources via pathToFileURL: 63 passed / 0 failed.
  • Jest test files validated with a shim runner (describe/it/expect): 44 passed / 0 failed (20 cache + 24 householdLoader).
  • Secret scan python tools/check_secrets.py: [OK], SECRETS_EXIT=0.
  • git push fork fix/issue-2264-household-cache: exit 0 (no force, no push to fork main).

Payouts

  • Base Mainnet (USDC/ETH): 0xC5dD2Ea54FF138bb3f71D3466092eA31eF115868
  • Solana (USDC/SOL): DN3pfYEvdkoTBP4oaEVvemsr98fZPhDSAbfVfmewRGQ5
  • PayPal: ivanzenteno3@gmail.com

@github-actions
github-actions Bot merged commit c9970ad into Smartdevs17:main Nov 24, 2026
7 of 27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cache household membership resolution with request-scoped loader

1 participant