LibreChat/packages/api/src/cache
Danny Avila a613caced3
🧊 fix: In-Memory Endpoint Token Config Cache Isolation (#12673)
* fix: endpoint token config not using shared cache in same process (initializing clients)

* refactor: Update default max context tokens for agent initialization

- Introduced a constant `DEFAULT_MAX_CONTEXT_TOKENS` set to 32000.
- Updated the `initializeAgent` function to use this constant instead of hardcoded values for maximum context tokens, improving maintainability and clarity.

* refactor: shared caching mechanism for token configuration

- Introduced a memoized in-memory cache for Keyv instances to ensure shared access across the same namespace, improving cache efficiency.
- Updated the `standardCache` function to utilize the new in-memory cache for the TOKEN_CONFIG namespace.
- Refactored the `initializeCustom` function to use the `tokenConfigCache` for better cache management.
- Removed redundant tokenCache parameter from `fetchModels` to streamline the function signature.

* fix: match TOKEN_CONFIG TTL and add memoization tests

Pass Time.THIRTY_MINUTES to tokenConfigCache() to match the TTL used
by getLogStores.js, preventing load-order-dependent expiry behavior.

Add 7 automated tests covering in-memory memoization: referential
identity, cross-call-site data sharing, namespace isolation,
first-caller TTL semantics, fallbackStore bypass, and tokenConfigCache
parity with direct standardCache access.

* fix: export DEFAULT_MAX_CONTEXT_TOKENS, address review nits

- Export the constant so tests (and future consumers) reference it
  directly instead of hardcoding the numeric value.
- Add independent TTL assertion for tokenConfigCache (R-1 nit).
- Add tokenConfigCache mock to custom/initialize.spec.ts.
2026-04-15 09:41:42 -04:00
..
__tests__ 🧊 fix: In-Memory Endpoint Token Config Cache Isolation (#12673) 2026-04-15 09:41:42 -04:00
cacheConfig.ts 🌊 refactor: Local Snapshot for Aggregate Key Cache to Avoid Redundant Redis GETs (#12422) 2026-03-26 16:39:09 -04:00
cacheFactory.ts 🧊 fix: In-Memory Endpoint Token Config Cache Isolation (#12673) 2026-04-15 09:41:42 -04:00
index.ts 📡 refactor: MCP Runtime Config Sync with Redis Distributed Locking (#10352) 2025-12-11 16:36:15 -05:00
keyvFiles.ts
keyvMongo.ts ⚙️ chore: Resolve Build Warning, Package Cleanup, Robust Temp Chat Time (#9962) 2025-10-04 01:53:37 -04:00
redisClients.ts ⚛️ refactor: Redis Scalability Improvements for High-Throughput Deployments (#11840) 2026-02-18 00:04:33 -05:00
redisUtils.ts 📡 refactor: MCP Runtime Config Sync with Redis Distributed Locking (#10352) 2025-12-11 16:36:15 -05:00