Course contentsShow
← Computer Science
Lesson 1119 of 2,87226. Memory Hierarchy and CachingFree lesson

Cache Hit vs Cache Miss

What happens when requested data is found in cache (hit) versus not found (miss) and must fetch from memory.

Cache Hit vs Cache Miss

You'll learn: What happens when the CPU finds data in the cache versus when it has to retrieve data from slower main memory.

The Two Possible Outcomes

When a CPU requests data, it first checks the cache (the small, fast memory layer closest to the processor). One of two things happens:

Cache Hit

A cache hit occurs when the requested data is found in the cache. This is the best-case scenario:

  • The CPU gets the data almost instantly
  • No need to access slower main memory
  • The program continues executing with minimal delay

Think of it like looking for your keys on the hook by the door — you check there first, find them immediately, and walk out. Fast and efficient!

Cache Miss

A cache miss occurs when the requested data is not in the cache. Now the CPU must:

  1. Access main memory (much slower)
  2. Retrieve the data
  3. Often load that data into the cache for future use
  4. Finally deliver it to the CPU

This is like checking the key hook, not finding your keys there, and having to search the entire house. It takes significantly longer.

Why This Matters

The difference in time between a hit and a miss is substantial — cache access might take 1-5 nanoseconds, while main memory access can take 50-100+ nanoseconds. That's a 10-50× slowdown on a miss!

Programs with good locality of reference (which you learned earlier) maximize cache hits by repeatedly accessing nearby data that stays cached.

Key Takeaway: A cache hit means fast access because data is found in cache; a cache miss means slower access because the CPU must fetch from main memory — the hit rate directly determines your program's memory performance.