Files
system-design-101/data/guides/most-popular-cache-eviction.md
Kamran Ahmed ee4b7305a2 Adds ByteByteGo guides and links (#106)
This PR adds all the guides from [Visual
Guides](https://bytebytego.com/guides/) section on bytebytego to the
repository with proper links.

- [x] Markdown files for guides and categories are placed inside
`data/guides` and `data/categories`
- [x] Guide links in readme are auto-generated using
`scripts/readme.ts`. Everytime you run the script `npm run
update-readme`, it reads the categories and guides from the above
mentioned folders, generate production links for guides and categories
and populate the table of content in the readme. This ensures that any
future guides and categories will automatically get added to the readme.
- [x] Sorting inside the readme matches the actual category and guides
sorting on production
2025-03-31 22:16:44 -07:00

2.5 KiB
Raw Permalink Blame History

title, description, image, createdAt, draft, categories, tags
title description image createdAt draft categories tags
Cache Eviction Policies Explore popular cache eviction strategies and their impact on performance. https://assets.bytebytego.com/diagrams/0281-most-popular-cache-eviction.png 2024-02-24 false
caching-performance
Caching
Algorithms

What are the most popular Cache Eviction strategies? And how do they work?

Caching can provide a boost to your applications performance by storing data in memory for faster access.

But when the cache gets full, you need to evict some data to make room for new stuff.

This is where cache eviction strategies come into play.

The strategy you choose can have a significant impact on your system's performance, memory usage, and hit rates. Here are five popular strategies to consider:

Time-to-Live (TTL)

Items are evicted after a predetermined time period, regardless of access patterns. Its simple to implement but can lead to premature eviction of frequently used data. TTL is suitable for data that is only valid for a certain period of time such as session information. It is also used as a default fallback strategy.

Least-Recently Used (LRU)

Evicts the least recently accessed items first. This strategy works well when access patterns exhibit temporal locality, i.e., recently accessed items are likely to be accessed again soon.

Least Frequently Used (LFU)

Evicts the least frequently accessed items first. Suitable when some items are accessed more often than others, and you want to keep only the most popular items in the cache. However, you also need a mechanism to maintain a count of the number of times an item is accessed.

Most Recently Used (MRU)

Evicts the most recently accessed items first. Counterintuitive but useful in specific scenarios like operating system buffer caches, where recently evicted items are unlikely to be needed again soon. Also useful in streaming or batch-processing requirements.

Segmented LRU (SLRU)

Divides the cache into probationary and protected segments, applying LRU separately to each. Newly added items go into the probationary segment, and frequently accessed items are promoted to the protected segment, shielding them from being evicted too soon.

The best caching strategy depends on the context of your system requirements and constraints. But having a broad understanding of them can help make the right choice.

Over to you: have you used any other cache eviction strategy?