Explain how TinyLFU decides whether a new key may enter a full cache, and what the sketch is for.
Sketch your own answer first, then compare it with the one below.
A strong answer
TinyLFU is an admission policy. When a missed key arrives at a full cache, the cache identifies a victim, the key its eviction policy would remove. TinyLFU admits the newcomer only if its estimated access frequency is higher than the victim's. Otherwise the newcomer is dropped and the victim stays.
Frequencies come from a count-min sketch: a small table of counters indexed by several hash functions. An estimate is the minimum over the counters for a key. It can overestimate because of collisions but never underestimate, and it uses a small fixed amount of memory no matter how many keys exist. That is what makes it practical to track the frequency of keys that are not in the cache, which exact counting could not afford.
To keep frequencies fresh, the counters are periodically halved. This aging lets new popularity overtake old and addresses the staleness of plain LFU.
Typical deployments pair the admission filter with an LRU-style main area, often segmented, and sometimes a small window in front so that a burst of new items gets a fair chance.
Sources
- Gil Einziger, Roy Friedman, Ben Manes (2017). TinyLFU: A Highly Efficient Cache Admission Policy.
- Graham Cormode, S. Muthukrishnan (2005). An improved data stream summary: the count-min sketch and its applications.