Skip to main content

Command Palette

Search for a command to run...

We're All Doing Caching Wrong (Here's the Right Way)

Published
2 min read

Old Way vs New Way of Caching – What’s Better?

There are basically two ways to cache:

1️⃣ The Old Way
2️⃣ The New Way

Most people assume the new way is always better. But that’s not true.

When designing your system, you should always think about business needs first. Is this an MVP (Minimal Viable Product)? Or a high-scale application?

Example: Caching a Product List

Imagine you have a product table with multiple items.

  • Old Way: Cache the entire product list at once.

  • New Way: Cache each product individually (loop through and store them separately).

Let’s have a look at a simple typescript code.

Old Way

const cacheKey = "products";
const products = await prisma.product.findMany({});
await redis.set(cacheKey, products);

New Way

let cacheKey;
const products = await prisma.product.findMany({});
products.forEach(product => (
    cacheKey = `product-${productId}`;
    await redis.set(cacheKey, product);
))

What’s the Difference?

  • New Way: If you update just one product’s quantity, you only update that product’s cache. The rest stays untouched.

  • Old Way: You delete the entire cache, update the product, and re-cache everything—otherwise, you’ll serve stale data.

So, Which One Should You Use?

  • Scaling?New Way (Better for performance at scale)

  • MVP or Low Traffic?Old Way (Simpler, less code)

It’s all about trade-offs. Choose based on what your business actually needs.

More from this blog

System Design

10 posts