Your question is Thread-Safe Inference Result 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.
Arrowstreet Capital's model inference service repeatedly requests results for the same input features. Implement a fixed-capacity, thread-safe least recently used (LRU) cache that stores pre-computed inference results.
The cache must support get and put operations. A successful get marks the key as most recently used. When inserting a new key would exceed capacity, evict the least recently used key. Updating an existing key also makes it most recently used. Every cache operation must be protected so concurrent callers cannot corrupt the cache's internal state.
Implement cache_inference_results(capacity, operations).
capacity is an integer greater than zero.operations is a list of dictionaries. Each dictionary is either {"op": "get", "key": string} or {"op": "put", "key": string, "value": integer}.get operation.None for a miss.def cache_inference_results(capacity, operations):