The video is on YouTube, which needs a VPN on most networks in mainland China. It is extra: the lesson works without it.
Try before notes
Which is nearer the ALU: a register or a file on an SSD?
Build the idea
Registers, cache, RAM and persistent storage solve different problems. Registers are tiny immediate workspaces. Cache keeps copies of recently or frequently useful memory data. RAM holds active programs and data. Persistent storage keeps saved work without power.
A cache hit finds the item in cache. A miss requires a lower-level access; it does not mean that the data vanished. Cache benefits depend on reuse and access patterns. A larger cache is not a promise of the same speed-up for every program.
Our toy cache uses least recently used replacement. After every access, move the accessed item to the most-recent position. On a miss into a full cache, remove the least-recent item first.
registers → cache → RAM → persistent storage
small fast workspace larger saved data
See the method
Registers hold immediate working values. Cache holds copies likely to be used soon. L1 is normally smaller and nearer the core than L2 and L3. RAM holds active programs and data. ROM is non-volatile storage for firmware in the simplified model. On a cache miss the item must be obtained from a lower level. Real cache layouts differ.
X: miss [X]. Y: miss [X,Y]. X: hit [Y,X]. Z: miss, evict Y, leaving [X,Z]. Revisiting X changed its recency.
A student saves a file to SSD, then loses power. Which data should survive: the saved file or unsaved edits held only in RAM?
Reveal reasoning
The saved SSD file should survive normal power loss because SSD storage is non-volatile. Edits held only in volatile RAM are lost. Applications may have autosave, but this scenario says the edits exist only in RAM.
Work one step together
Read the first task. Each learner predicts the first step privately. Compare the method, then complete one intermediate row or one code iteration together. Do not display a finished workbook answer.
Practice
A toy cache holds two items. On a miss it loads the item and evicts the least recently used item if full. Trace requests A,B,A,C,A,B from empty. Mark hit or miss and show the cache from least to most recent.
Your turn
Complete the remaining steps of task 1 alone, then the next tasks. Predict before running code. Save your own evidence before comparing.
Practice
A toy cache holds two items. On a miss it loads the item and evicts the least recently used item if full. Trace requests A,B,A,C,A,B from empty. Mark hit or miss and show the cache from least to most recent.
A laptop has slow repeated calculations and too little RAM for its open files. Explain one role of cache and one role of RAM. Why would adding SSD space alone not make them equivalent?
Check and explain
More SSD capacity does not turn the SSD into RAM or cache.
Point to the first step, row, condition or requirement that supports your answer. If results differ, find the first different state and repair one cause.
Show what you know
Does a cache miss mean the data is lost?
HL challenge when ready
Would every program gain equally from a larger cache?
Week 3 homework
Show working. Keep code and output. Stop at 25 minutes and mark where you reached.
In the toy machine PC=4. Memory 4 contains LOAD 20 and memory 20 holds 9. Trace the fetch and execute.
Explain why cache, RAM and SSD are not interchangeable. Use one job for each.
Six independent instructions use F,D,E,W with no stalls. Find the ideal cycles and compare with no overlap. Write ideal_cycles(n) in Python for n >= 1. Test n = 1, 4 and 6.
Retrieve logic: simplify (A AND B) OR (A AND NOT B). Give one proof step.
Spend about 3 minutes on each during practice time. Predict, run, change one thing, then explain. These prompts do not add homework.
A starter is runnable code to explore or complete. If the playground restores your saved code, the linked starter is selected in Example: use Load example when ready. Download your work before confirming replacement.
Prompt 1
Count cache hits for this access sequence. Add one new address and predict the count.
No imports needed.
Hint and starter code
A cache hit means the requested item is already in a fast local copy; this fixed set does not model replacement.
# A cache hit means the requested item is already in a fast local copy; this fixed set does not model replacement.
cache = {1, 3}
accesses = [1, 2, 3, 1]
hits = 0
for address in accesses:
if address in cache:
hits += 1
print(hits)