2dbi
Home/Cloudflare/Implement an LFU / TTL Cache
CCloudflare·DSASWE-2Onsite – Coding (Practical)

Implement an LFU / TTL Cache

Problem

Implement a cache with TTL expiry and an eviction policy (LFU or LRU) in O(1) operations.

Example

get/put with per-key TTL; evict on capacity

Constraints

  • High request rate

Approach

Hash map + frequency buckets (LFU) or doubly linked list (LRU); lazy TTL on access.

added 6 days ago
LeadersAccount