The backend calls a paid API billed per request. Someone 'optimized' costs with a cache on a global map and not a single lock — now the service crashes under load and the invoice still looks like an inside-job DDoS. Build an LRU cache that survives concurrency: mutex, RAII, and eviction.
Implement a generic ThreadSafeCache<Key, Value> with LRU eviction. It must be safe under concurrent access from multiple threads with no data races.
std::mutex (or std::shared_mutex for reader optimization)get must update recency (a get is a "use")shared_mutex help versus hurt performance here?Combine a list for recency order with an unordered_map from key to list iterator for O(1) access.
Lock a std::mutex with lock_guard at the start of every public method.
On get/put, splice the touched node to the front; when over capacity, evict from the back.
Hit Submit (or ⌘/Ctrl + ↵) — test results will show up here.