Your question is Memory-Layered LRU Cache. 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.
Cloudflare Workers can use an in-memory cache layer to avoid repeatedly computing or fetching recently used values. Implement a fixed-capacity LRU cache where the least recently used entry is evicted when the cache is full.
Use a hash map for direct key lookup and a doubly linked list to maintain recency. The most recently used entry must be at the front of the list, and the least recently used entry must be at the back.
Implement lru_cache_operations(capacity, operations):
capacity is a positive integer.operations is a list of operations. ['get', key] reads a value, and ['put', key, value] inserts or updates a value.get operation, in order.-1.get and every put mark the key as most recently used.def lru_cache_operations(capacity, operations):