The LRU Cache problem starts with an implementation most engineers have written at least once: a dictionary and a doubly linked list that together evict the least recently used entry when the cache reaches capacity. This version adds a time-to-live for each entry, and later a get_or_load method that many threads call at once.
The round has four phases:
ttl, peek, delete and stats while following seven rules.get_or_load where callers requesting the same key share one load, without holding the lock while the loader runs.The main challenge is that expiration affects almost every part of the cache. Reading an entry updates its recency but doesn't extend its lifetime. Expired entries must give up their slots before any live entry is evicted, and they don't count as evictions. And if someone writes to a key while a load for it is still running, the load must not overwrite that newer value.