mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-07-10 16:23:44 +00:00
🔧 refactor: Update cache configuration for in-memory storage handling
- Enhanced the handling of `FORCED_IN_MEMORY_CACHE_NAMESPACES` in `cacheConfig.ts` to default to `CONFIG_STORE` and `APP_CONFIG`, ensuring safer blue/green deployments. - Updated `.env.example` with clearer comments regarding the usage of in-memory cache namespaces. - Improved unit tests to validate the new default behavior and handling of empty strings for cache namespaces.
This commit is contained in:
parent
fa7bff2083
commit
e6e61f5e28
3 changed files with 14 additions and 9 deletions
|
|
@ -748,10 +748,10 @@ HELP_AND_FAQ_URL=https://librechat.ai
|
|||
# REDIS_PING_INTERVAL=300
|
||||
|
||||
# Force specific cache namespaces to use in-memory storage even when Redis is enabled
|
||||
# Comma-separated list of CacheKeys (e.g., ROLES,MESSAGES)
|
||||
# For blue/green deployments, keep YAML-derived config per-container while sharing tools via Redis:
|
||||
# Comma-separated list of CacheKeys
|
||||
# Defaults to CONFIG_STORE,APP_CONFIG so YAML-derived config stays per-container (safe for blue/green deployments)
|
||||
# Set to empty string to force all namespaces through Redis: FORCED_IN_MEMORY_CACHE_NAMESPACES=
|
||||
# FORCED_IN_MEMORY_CACHE_NAMESPACES=CONFIG_STORE,APP_CONFIG
|
||||
# FORCED_IN_MEMORY_CACHE_NAMESPACES=ROLES,MESSAGES
|
||||
|
||||
# Leader Election Configuration (for multi-instance deployments with Redis)
|
||||
# Duration in seconds that the leader lease is valid before it expires (default: 25)
|
||||
|
|
|
|||
|
|
@ -215,16 +215,16 @@ describe('cacheConfig', () => {
|
|||
}).rejects.toThrow('Invalid cache keys in FORCED_IN_MEMORY_CACHE_NAMESPACES: INVALID_KEY');
|
||||
});
|
||||
|
||||
test('should handle empty string gracefully', async () => {
|
||||
test('should produce empty array when set to empty string (opt out of defaults)', async () => {
|
||||
process.env.FORCED_IN_MEMORY_CACHE_NAMESPACES = '';
|
||||
|
||||
const { cacheConfig } = await import('../cacheConfig');
|
||||
expect(cacheConfig.FORCED_IN_MEMORY_CACHE_NAMESPACES).toEqual([]);
|
||||
});
|
||||
|
||||
test('should handle undefined env var gracefully', async () => {
|
||||
test('should default to CONFIG_STORE and APP_CONFIG when env var is not set', async () => {
|
||||
const { cacheConfig } = await import('../cacheConfig');
|
||||
expect(cacheConfig.FORCED_IN_MEMORY_CACHE_NAMESPACES).toEqual([]);
|
||||
expect(cacheConfig.FORCED_IN_MEMORY_CACHE_NAMESPACES).toEqual(['CONFIG_STORE', 'APP_CONFIG']);
|
||||
});
|
||||
|
||||
test('should accept TOOL_CACHE as a valid namespace', async () => {
|
||||
|
|
|
|||
11
packages/api/src/cache/cacheConfig.ts
vendored
11
packages/api/src/cache/cacheConfig.ts
vendored
|
|
@ -27,9 +27,14 @@ const USE_REDIS_STREAMS =
|
|||
|
||||
// Comma-separated list of cache namespaces that should be forced to use in-memory storage
|
||||
// even when Redis is enabled. This allows selective performance optimization for specific caches.
|
||||
const FORCED_IN_MEMORY_CACHE_NAMESPACES = process.env.FORCED_IN_MEMORY_CACHE_NAMESPACES
|
||||
? process.env.FORCED_IN_MEMORY_CACHE_NAMESPACES.split(',').map((key) => key.trim())
|
||||
: [];
|
||||
// Defaults to CONFIG_STORE,APP_CONFIG so YAML-derived config stays per-container.
|
||||
// Set to empty string to force all namespaces through Redis.
|
||||
const FORCED_IN_MEMORY_CACHE_NAMESPACES =
|
||||
process.env.FORCED_IN_MEMORY_CACHE_NAMESPACES !== undefined
|
||||
? process.env.FORCED_IN_MEMORY_CACHE_NAMESPACES.split(',')
|
||||
.map((key) => key.trim())
|
||||
.filter(Boolean)
|
||||
: [CacheKeys.CONFIG_STORE, CacheKeys.APP_CONFIG];
|
||||
|
||||
// Validate against CacheKeys enum
|
||||
if (FORCED_IN_MEMORY_CACHE_NAMESPACES.length > 0) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue