Repository navigation
feat(cache): household membership cache (closes #2264) - #2323
Merged
github-actions[bot] merged 1 commit intoNov 24, 2026
Merged
github-actions[bot] merged 1 commit into
github-actions[bot] merged 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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, frozenDEFAULT_CACHE_CONFIGwith injectable clock), noop metrics/logger hooks, andcreateTtlCache<T>()returning a frozen handle withget/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: typedHouseholdLoaderError/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.cache.test.ts(20 assertions) andhouseholdLoader.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/libengine 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
.tssources viapathToFileURL: 63 passed / 0 failed.python tools/check_secrets.py:[OK], SECRETS_EXIT=0.git push fork fix/issue-2264-household-cache: exit 0 (no force, no push to forkmain).Payouts