← Lessons

quiz vs the machine

Gold1390

Databases

Near Cache and Client Side Caching

Keep a small copy beside the application to cut latency and remote round trips.

4 min read · core · beat Gold to climb

A Cache in Front of the Cache

A near cache is a small in process cache that sits inside the application, in front of a shared remote cache or database. Hits are served from local memory with no network call, making them dramatically faster. The remote cache becomes a second tier for misses.

The Invalidation Challenge

The hard part is keeping local copies fresh. If the shared value changes, every application instance holding a stale copy must learn about it. Common approaches include:

  • Time based expiry where entries simply expire after a short window, accepting brief staleness.
  • Invalidation messages where the server pushes a notice so clients drop the affected key. Redis client side caching uses this tracking mechanism.

When To Use It

Near caches shine for small, frequently read, slowly changing data such as configuration or reference tables. They are a poor fit for data that changes constantly or must be perfectly consistent across instances.

Key idea

A near cache holds a small local copy beside the application to serve hot reads with no network hop, at the cost of having to invalidate stale entries across instances.

Check yourself

Answer to earn rating on the learn ladder.

1. What is the main benefit of a near cache?

2. What is the central challenge of a near cache?