Caching
ELI5 — The Vibe Check
Caching is saving the result of a slow operation so you can reuse it quickly next time. Instead of asking the database for the same data 1,000 times, you ask once, save the answer, and return the saved answer for the next 999 requests. Huge speed boost.
Real Talk
Caching stores the results of expensive operations (DB queries, API calls, computations) in fast-access storage (memory, Redis) so future requests can be served without repeating the work. Cache entries have a TTL (time-to-live) after which they're invalidated.
Show Me The Code
// Check cache first, then DB
const cached = await redis.get('user:42');
if (cached) return JSON.parse(cached);
const user = await db.user.findById(42);
await redis.setex('user:42', 3600, JSON.stringify(user));
return user;
When You'll Hear This
"Cache the homepage data for 5 minutes." / "The cache is stale — invalidate it."
Related Terms
Memcached
Memcached is Redis's simpler sibling — an in-memory cache that's great at one thing: storing key-value pairs really fast.
Rate Limiting
Rate limiting is like a bouncer who says 'you can come in 100 times per hour, then you wait.
Redis
Redis is an incredibly fast database that lives entirely in memory (RAM). It's used as a cache, a session store, and a message queue.