[GH-ISSUE #4049] Backend Architecture: Implement Redis Caching Layer #2575

Closed
opened 2026-02-22 18:30:20 -05:00 by yindo · 0 comments
Owner

Originally created by @jezweb on GitHub (Jun 26, 2025).
Original GitHub issue: https://github.com/Mintplex-Labs/anything-llm/issues/4049

Overview

Implement a multi-tier caching strategy using Redis to improve performance and reduce database load.

Related to upstream discussion: https://github.com/Mintplex-Labs/anything-llm/issues/2797

Current State

  • Basic database caching with cache_data table
  • No in-memory caching
  • No distributed cache support

Proposed Architecture

1. Multi-tier Cache

  • L1: In-process memory cache (LRU) - microseconds
  • L2: Redis distributed cache - milliseconds
  • L3: Database cache table - backup/persistence

2. Cache Implementation Points

High-Frequency Caches (TTL: 1-5 minutes)

  • User sessions and permissions
  • Workspace metadata
  • Active chat contexts
  • System configuration

Medium-Frequency Caches (TTL: 1 hour)

  • Vector search results
  • Document metadata
  • Workspace statistics
  • User preferences

Long-Term Caches (TTL: 24 hours)

  • LLM responses for identical queries
  • Processed document content
  • Embedding results
  • Static resource metadata

3. Redis Features to Utilize

  • Key expiration (TTL)
  • Pub/Sub for cache invalidation
  • Lua scripts for atomic operations
  • Redis Streams for event sourcing

Implementation Plan

Phase 1: Infrastructure

  1. Add Redis dependency and client
  2. Create cache service abstraction
  3. Implement connection pooling
  4. Add health checks

Phase 2: Core Caching

  1. Session/auth caching
  2. Workspace metadata caching
  3. Vector search result caching
  4. Configuration caching

Phase 3: Advanced Features

  1. Cache warming strategies
  2. Cache invalidation patterns
  3. Distributed locking
  4. Performance monitoring

Benefits

  • 10-100x faster data access for cached items
  • Reduced database load by 40-60%
  • Better horizontal scalability
  • Improved user experience

Configuration

REDIS_ENABLED=true
REDIS_HOST=localhost
REDIS_PORT=6379
REDIS_PASSWORD=
REDIS_DB=0
CACHE_TTL_DEFAULT=3600

Labels: enhancement, performance, backend, architecture

Originally created by @jezweb on GitHub (Jun 26, 2025). Original GitHub issue: https://github.com/Mintplex-Labs/anything-llm/issues/4049 ## Overview Implement a multi-tier caching strategy using Redis to improve performance and reduce database load. Related to upstream discussion: https://github.com/Mintplex-Labs/anything-llm/issues/2797 ## Current State - Basic database caching with `cache_data` table - No in-memory caching - No distributed cache support ## Proposed Architecture ### 1. Multi-tier Cache - **L1**: In-process memory cache (LRU) - microseconds - **L2**: Redis distributed cache - milliseconds - **L3**: Database cache table - backup/persistence ### 2. Cache Implementation Points #### High-Frequency Caches (TTL: 1-5 minutes) - User sessions and permissions - Workspace metadata - Active chat contexts - System configuration #### Medium-Frequency Caches (TTL: 1 hour) - Vector search results - Document metadata - Workspace statistics - User preferences #### Long-Term Caches (TTL: 24 hours) - LLM responses for identical queries - Processed document content - Embedding results - Static resource metadata ### 3. Redis Features to Utilize - Key expiration (TTL) - Pub/Sub for cache invalidation - Lua scripts for atomic operations - Redis Streams for event sourcing ## Implementation Plan ### Phase 1: Infrastructure 1. Add Redis dependency and client 2. Create cache service abstraction 3. Implement connection pooling 4. Add health checks ### Phase 2: Core Caching 1. Session/auth caching 2. Workspace metadata caching 3. Vector search result caching 4. Configuration caching ### Phase 3: Advanced Features 1. Cache warming strategies 2. Cache invalidation patterns 3. Distributed locking 4. Performance monitoring ## Benefits - 10-100x faster data access for cached items - Reduced database load by 40-60% - Better horizontal scalability - Improved user experience ## Configuration ```env REDIS_ENABLED=true REDIS_HOST=localhost REDIS_PORT=6379 REDIS_PASSWORD= REDIS_DB=0 CACHE_TTL_DEFAULT=3600 ``` Labels: enhancement, performance, backend, architecture
yindo closed this issue 2026-02-22 18:30:20 -05:00
yindo changed title from Backend Architecture: Implement Redis Caching Layer to [GH-ISSUE #4049] Backend Architecture: Implement Redis Caching Layer 2026-06-05 14:47:21 -04:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Mintplex-Labs/anything-llm#2575