← Questions
Key-value cache with per-entry TTL
0
I was asked this
No reports yet. Sign in to say where you were asked it.
Implement an in-memory key-value cache where every write gives a key, a value and a time-to-live. Once an entry's time is up it must behave as if it was never written. Support set, get and delete, and explain your choices as you go.
Follow-ups that come up:
-
getis the hot path, so keep it cheap and move cleanup of expired entries elsewhere (a background sweeper or sidecar). How do you find expired entries without scanning everything? - Add a capacity limit with least-recently-used eviction on top of the expiry.
- Make it safe for concurrent callers.
- Write and run tests, including ones that control the clock.
No official answer yet. Write yours on the right and run it.
Nothing published yet.
Sign in to submit your code; every attempt is kept here.
Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding
