A cache hit occurs when requested data or instructions are found in cache memory. A cache miss occurs when they are not found, so they must be retrieved from a slower level of the memory hierarchy.
How the Mechanism Works
A cache is a small, high-speed memory located in or close to the CPU. It stores copies of recently or frequently accessed data and instructions, reducing the time needed to access slower main memory (RAM).
When the CPU requests a memory address:
- The cache controller checks whether the relevant block is stored in the cache.
- It compares the address information with a tag associated with a cache line.
- If a valid matching tag is found, a cache hit occurs and the data is supplied quickly.
- If no match is found, a cache miss occurs. The block is retrieved from the next cache level or RAM and is usually copied into the cache for future access.
Caching is effective because programs demonstrate locality of reference: recently accessed data is likely to be accessed again, and nearby memory locations are often accessed soon afterward.
| Feature | Cache hit | Cache miss |
|---|---|---|
| Data location | Already in the cache | Not currently in the cache |
| Access speed | Fast | Slower |
| CPU effect | Little or no waiting | May cause the CPU to wait |
| Cache action | Return the stored data | Fetch and usually cache the required block |
The hit rate is the proportion of memory accesses that produce hits. If 80 of 100 accesses are hits, the hit rate is , or . A higher hit rate generally improves system performance.
Exam Technique
For a question using the command term distinguish, define both outcomes and state their performance effects. Avoid the common misconception that a cache miss is an error: it simply means the requested item must be obtained from slower memory.