BeginnerCoder

Lesson 25 — Ultimate: KV store with TTL

Boss level: a mini Redis

Redis is a popular in-memory key-value store: you set a value under a key and get it back very fast. Memory is limited, so when the store is full it evicts (removes) an old key. A JavaScript Map remembers insertion order, so m.keys().next().value is the oldest key.

const oldest = m.keys().next().value;
m.delete(oldest);

Note: this playground runs JavaScript in your browser, not in real Node, so Node-only tools (like fs or http) are not available. The exercise is a small plain-JS simulation of the Node idea.

Why it matters: caching layers like this sit in front of almost every busy backend.

Want it another way?
Task

In set(), when the store is full and k is a new key, delete the oldest key first.

Run your code — when the output matches the task, you will see a green check. Then mark the lesson complete.

Test your knowledge

A quick 3-question quiz on this lesson — instant feedback.

Enjoying this lesson? Share it.

Keep going with Node.js Foundations

Ready for more? Optional paid resources that pick up where this lesson leaves off.

Some links on this page are affiliate links: we may earn a commission at no extra cost to you. As an Amazon Associate I earn from qualifying purchases.