An open API service indexing awesome lists of open source software.

https://github.com/kavicastelo/advanced-cache-design

A collection of advanced cache design algorithms including LRU, LFU, ARC, TinyLFU, Count-Min Sketch, and Segmented LRU, implemented in TypeScript.
https://github.com/kavicastelo/advanced-cache-design

arc-cache cache-design count-min-sketch lfu-cache lru-cache slru-cache system-design tinylfu

Last synced: 5 months ago
JSON representation

A collection of advanced cache design algorithms including LRU, LFU, ARC, TinyLFU, Count-Min Sketch, and Segmented LRU, implemented in TypeScript.

Awesome Lists containing this project

README

          

# Advanced Cache Design Algorithms (LRU, LFU, ARC, TinyLFU, SLRU, CMS)

This repository contains **production-quality, educational implementations** of modern cache eviction and admission algorithms used in systems such as:

- Redis
- ZFS
- Cloudflare CDN
- YouTube backend services
- Google’s Caffeine Cache
- OS kernel memory managers

These implementations are written in **TypeScript**, focusing on clarity and correctness.

---

## πŸš€ Included Algorithms

### βœ”οΈ LRU (Least Recently Used)

Classical O(1) LRU using a doubly linked list + hash map.

### βœ”οΈ LFU (Least Frequently Used)

Full LFU with frequency lists and O(1) updates.

### βœ”οΈ ARC (Adaptive Replacement Cache)

Self-tuning hybrid of recency and frequency.

### βœ”οΈ TinyLFU (Admission Policy)

Modern frequency-based admission algorithm used by Google Caffeine.

### βœ”οΈ SLRU (Segmented Least Recently Used)

Two-tier LRU that protects hot entries from eviction.

### βœ”οΈ CMS (Count-Min Sketch)

Probabilistic frequency estimator (used by huge-scale caches).

---

## πŸ“¦ Installation

```bash
git clone https://github.com/kavicastelo/advanced-cache-design.git
cd advanced-cache-design
npm install
```

---

## ▢️ Running Examples

```bash
npm run build
node dist/examples/test-lru.js
```

Want scripts for all algorithms? Just run:

```bash
node dist/examples/test-*.js
```

---

## πŸ“ Directory Overview

```text
src/
lru/ β†’ LRU cache implementation
lfu/ β†’ LFU cache implementation
arc/ β†’ ARC hybrid cache
cms/ β†’ Count–Min Sketch
tiny-lfu/ β†’ TinyLFU admission
slru/ β†’ Segmented LRU eviction
examples/ β†’ Demo scripts
```

---

## 🧰 Technologies Used

- TypeScript
- Node.js
- Modern data structure design
- Systems design best practices

---

## πŸ“ License

[MIT](LICENSE) License – Free to use and modify.