Distributed Caching

Cache Eviction Policies

Cache Eviction Policies

A cache is transient storage, meaning it’s short-lived. The small amount of cache limits the amount of data to store.

We need to track the data we store or remove over time. There are a number of algorithms that are used to manage the memory of a cache:

Least Recently Used (LRU)

The cache discards the least recently used data. It’s implemented using a timestamp for the last access.

If the data has not been used recently, we assume the chances of being called are less compared to others so removing it provides space for more recent data in the cache.

Least Frequently Used (LFU)

In this policy, we count the number of times a cache item is accessed. The one with the least use is discarded first. It’s assumed that the least used data are wasting space.

First In First Out (FIFO)

This policy works like a queue. The cache evicts data that is accessed first. It does not consider the number of times that data has been accessed before.

Last In First Out (LIFO)

This policy works like a stack(LIFO). The cache removes data that is recently added.

Random Selection

Here, the system randomly selects a data item from the cache memory to give space when necessary.

Whenever you're ready

There are 4 ways we can help you become a great backend engineer:

The MB Platform

Join 1000+ backend engineers learning backend engineering. Build real-world backend projects, learn from expert-vetted courses and roadmaps, track your learnings and set schedules, and solve backend engineering tasks, exercises, and challenges.

The MB Academy

The “MB Academy” is a 6-month intensive Advanced Backend Engineering BootCamp to produce great backend engineers.

Join Backend Weekly

If you like post like this, you will absolutely enjoy our exclusive weekly newsletter, Sharing exclusive backend engineering resources to help you become a great Backend Engineer.

Get Backend Jobs

Find over 2,000+ Tailored International Remote Backend Jobs or Reach 50,000+ backend engineers on the #1 Backend Engineering Job Board