Your question is Thread-Safe LRU Cache with TTL. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Implement a class-based cache that supports get(key, now) and put(key, value, ttl, now) with capacity-limited LRU eviction and expiration. Each entry expires at time now + ttl; expired entries must behave as missing, and when capacity is full, the least recently used non-expired entry should be evicted. Design the cache so operations are thread-safe while keeping lock contention low.
def run_lru_ttl_cache(capacity, operations):