Redis Cache

Anonymous 17/Dec/2024(Tue)22:02:51 >>#0 ← reply
┌──────────────┐     ┌──────────────┐     ┌──────────────┐
│              │     │    Redis     │     │  PostgreSQL  │
│    User      │     │    Cache     │     │  Database    │
│              │     │              │     │              │
└──────┬───────┘     └──────┬───────┘     └──────┬───────┘
       │                     │                    │
       │  Request Page       │                    │
       │──────────────►│     │                    │
       │               │     │                    │
       │               │ Check Cache              │
       │               │◄────┐                    │
       │               │     │                    │
       │               │     │                    │
       │               │  If MISS                 │
       │               │─────────────────────────►│
       │               │                          │
       │               │      Query Data          │
       │               │◄─────────────────────────│
       │               │                          │
       │               │ Store in Cache           │
       │               │─────►│                   │
       │               │      │                   │
       │  Return Data  │      │                   │
       │◄──────────────┤      │                   │
       │               │      │                   │
       │               │      │                   │
       │  Next Request │      │                   │
       │─────────────�►│      │                   │
       │               │      │                   │
       │               │ Cache HIT                │
       │               │◄────┐                    │
       │  Return Data  │                          │
       │◄──────────────┤                          │
       │               │                          │
└──────┴───────┘     └──────┴───────┘     └──────┴───────┘
Anonymous >#1
This is how redis caching work in this website
Anonymous >#2
why? because https://www.youtube.com/watch?v=bFf-A27Rc9s Adding a cache is not as simple as it may seem... #First-Time Visit Workflow 1. User requests a board or thread page 2. Nejiboard checks Redis cache for the content 3. Cache MISS occurs (no data in Redis) 4. Application queries PostgreSQL database 5. Data is retrieved from PostgreSQL 6. Data is stored in Redis cache with 5-minute timeout 7. Content is served to the user #Subsequent Visit Workflow 1. User requests a board or thread page 2. Nejiboard checks Redis cache for the content 3. Cache HIT occurs (data found in Redis) 4. Content is served directly from Redis 5. No PostgreSQL query needed 6. Faster response time achieved Note: First-time visits always result in a PostgreSQL query, but the data is cached for subsequent visits. Cache entries expire after 5min, after which the process reverts to the first-time workflow
Anonymous >#3
#Cache Invalidation Cases 1. New thread is created: Board cache is clered 2. New reply is posted: Both board and thread cache are cleared 3. Thread is deleted: Board cache is cleared 4. Thread is pinned/unpinned: Board cache is cleared 5. Thread is locked/unlocked: Thread cache is cleared 6. Admin actions: Relevant caches are cleared

Formatting: **bold**, *italic*, __bright red__, >greentext, >>1 (quote post), [ascii]your art[/ascii]