In-Memory Cache with Eviction Policies

Company: kAIgentic-SDE_25may

Difficulty: medium

Problem Statement

In-Memory Cache with Eviction Policies Design a generic in-memory key-value cache whose eviction policy can be swapped. A natural design has a Cache interface with the operations below, one class per eviction policy, and a CacheFactory that builds the right cache from the policy name. The judge checks only the behaviour described here, through the function run_cache_operations . The cache holds at most capacity keys and supports these operations: put <key> <value> - store value under key . If key is already present, its value is replaced and nothing is evicted. If key is new and the cache already holds capacity keys, first evict one key chosen by the policy, then insert. get <key> - look key up. On a hit the result is its value; on a miss the result is None . delete <key> - remove key if present; deleting a missing key does nothing. size - the number of keys currently stored. It produces no output line. clear - remove every key. A key is accessed by a get that h