LearnViz CompSci
Home / Learn / Computer Architecture & Logic / Cache Memory

Intermediate Topic 26 of 51 Computer Architecture & Logic

Cache Memory

Small fast memory holding recently used data close to the CPU.

How it works

A cache is a small, fast memory that keeps copies of recently or frequently used data from slower memory. Data moves in fixed-size lines, typically 64 bytes, so nearby addresses come along. A hit returns data quickly, while a miss fetches it from the next level, and the hit rate and miss penalty determine average memory access time. Write policies include write-through and write-back.

Step-by-step walkthrough

  1. The CPU requests address 100.
  2. The cache has no copy, a miss.
  3. The cache fetches a whole line from memory.
  4. The line returns and is stored.
  5. The data goes to the CPU, and the next access to nearby data is a fast hit.

Where it is used

CPU caches, web browsers, content delivery networks, DNS resolvers and database buffers all use the same idea. Cache-friendly code keeps data compact and accessed sequentially.

Common pitfall

Misses come in types: compulsory, capacity and conflict. Poor data layout, pointer chasing and false sharing between threads degrade performance. Stale data is a danger in multicore and distributed caches, requiring coherence or invalidation. Do not assume the cache will fix algorithms with bad access patterns.

Where it fits in the course

Cache Memory is topic 26 of 51 in Computer Architecture & Logic, rated Intermediate. It follows Memory Hierarchy. The next topic is Cache Mapping.

Practice and explore

How to study this topic

  1. Read the explanation above and restate the definition in your own words.
  2. Open the interactive lesson and answer its mini quiz.
  3. Read the common pitfall, then write a short example that avoids it.
  4. Check your understanding in the Computer Architecture & Logic quiz, and revisit the topic if you miss a question.

Frequently asked questions

What is Cache Memory?
Small fast memory holding recently used data close to the CPU. It belongs to Computer Architecture & Logic and is an intermediate-level topic.
Where do people use Cache Memory?
CPU caches, web browsers, content delivery networks, DNS resolvers and database buffers all use the same idea.
What is the most common mistake with Cache Memory?
Misses come in types: compulsory, capacity and conflict.
What should I learn before this topic?
Start with Memory Hierarchy, the topic just before it in Computer Architecture & Logic.
How can I practice it?
Answer the mini quiz in the interactive lesson, then take the Computer Architecture & Logic quiz.
Is Cache Memory hard to learn?
It is an Intermediate topic. Be comfortable with the Beginner topics in this area first, then read the common pitfall carefully, since it is where most mistakes happen.
How long does it take to learn Cache Memory?
Most learners can read the explanation and finish the interactive lesson in under an hour. Fluency comes from applying the idea, so plan a few short practice sessions with the quiz.
Which topics are related to Cache Memory?
Memory Hierarchy, Cache Mapping, Addressing Modes are closely connected. The full list is in the related topics section of this page.
What should I study after Cache Memory?
Continue with Cache Mapping, the next topic in Computer Architecture & Logic.

Related topics