MainExamplesHistoryRecommended Reading
Explain /Computer Science

What is Caching?

Help others learn from this page

Caching stores frequently accessed data in fast storage so you don't have to recompute or re-fetch it. It's like keeping your most-used tools on your desk instead of in the garage — much faster to grab when you need them.

How It Works:

  1. First request: Compute/fetch data (slow)
  2. Store result in cache (fast storage)
  3. Next request: Return cached data (very fast!)
  4. Cache expires or gets invalidated
  5. Repeat

Types of Caches:

  • Browser cache: Stores web assets locally
  • CDN cache: Content delivery networks cache globally
  • Application cache: In-memory cache (Redis, Memcached)
  • Database cache: Query result caching
  • CPU cache: Hardware-level speed boost

Cache Strategies:

  • Cache-aside: App checks cache, fetches if miss
  • Write-through: Write to cache and database simultaneously
  • Write-back: Write to cache, sync to database later

Benefits:

  • Speed: Much faster than recomputing
  • Reduced load: Less work for databases/servers
  • Better UX: Faster response times

FAQ

What should I cache?
Frequently accessed, expensive to compute, and relatively static data. Don't cache user-specific, frequently changing, or sensitive data without care.
What's cache invalidation?
Removing or updating cached data when the source data changes. It's one of the hard problems in computer science!

Enjoyed this explanation? Share it!

Promote your content

Reach over 400,000 developers and grow your brand.

Join our developer community

Hang out with over 4,500 developers and share your knowledge.