Design a Local Cache System with Overflow Flush

viaGlassdoor

Requirements: Design a local (in-memory or on-disk) cache system that stores data and flushes (evicts) entries once the cache overflows a size limit.

Design considerations: Fixed capacity, eviction policy on overflow (commonly LRU - Least Recently Used), thread-safety if accessed concurrently, and persistence strategy (in-memory only vs disk-backed).

Approach: Implement using a hash map for O(1) key lookup combined with a doubly linked list to track recency order. On cache hit, move the accessed entry to the front (most recently used). On insert when at capacity, evict the entry at the back of the list (least recently used) before inserting the new one. Both get and put operate in O(1) time.

Add a follow-up question they asked
No follow-ups yet. Be the first to add one.
asked …
LeaderboardSalary
Language
Account