feat: implement distributed caching layer #1335
✓ Ready to merge enhancement performance
AX
@alexchen assigned to themself
📊 3 commits
📄 12 changed files
Conversation 4
Commits 3
Checks 6
Files changed 12
Description

Introduces a new distributed caching layer using Redis cluster with automatic failover and TTL-based eviction policies. This replaces the legacy in-memory singleton cache that was causing memory leaks under high load.

Key changes:

  • Connection pooling with circuit breaker pattern
  • Async serialization/deserialization using msgpack
  • Automatic shard discovery & rebalancing
  • Drop-in replacement for CacheManager
const cache = new DistributedCache({
  nodes: process.env.REDIS_NODES?.split(',') || [],
  ttl: 3600,
  serializer: 'msgpack'
});

Benchmark results show a 3.2x throughput increase and 40% reduction in p99 latency for cached endpoints. Ready for review & merge into develop.

MR
marcus_lee reviewed 2 hours ago

The circuit breaker implementation looks solid. One suggestion: consider adding a configuration flag to disable cluster mode for local dev environments to avoid pulling up a full Redis stack during testing.

src/cache/client.ts +3 -1
- export const CLUSTER_ENABLED = true;
+ export const CLUSTER_ENABLED = process.env.CACHE_CLUSTER_MODE === 'true';
AX
alexchen author commented 1 hour ago

@marcus_lee Agreed. I've updated the config loader to fallback to standalone mode when REDIS_NODES is undefined or empty. Also added a Dockerfile.cache-dev for easy local testing. Pushed to feat/cache-v2.

SJ
sarah_jenkins reviewed 45 minutes ago

LGTM! The serialization fallback to JSON is a nice safety net. Approving.