Implement a cache handling system, including defining and managing TTL (time-to-live) expiration, checking elapsed time, and determining when items should be deleted.
Asked in the Onsite Coding Round stage. Write code for cache handling and deal with TTL logic under tight time constraints.
Implement run_cache(operations). Each operation is a dictionary with op and a logical time. set also has key, value, and nonnegative ttl; get and delete have key; cleanup has only time. Return one result for each get, delete, or cleanup, in operation order. An expired or missing get returns None; delete returns a Boolean; cleanup returns expired keys in sorted order. An entry expires when time >= insertion_time + ttl.
def run_cache(operations):