



A mobile app at PulseFit calls several REST endpoints repeatedly. To reduce unnecessary network requests, implement an in-memory cache that stores API responses by endpoint key and expires entries after a fixed time-to-live.
Write a function that processes a sequence of cache operations and returns the result of each get operation.
Implement process_api_cache(operations, ttl) where:
operations is a list of operations.["set", key, value, timestamp]["get", key, timestamp]["invalidate", key, timestamp]key and value are strings.timestamp is a non-negative integer.ttl is a positive integer.For a get at time t, return the cached value only if the key exists and t - set_timestamp < ttl. Otherwise return "MISS". An invalidate removes the key immediately if present. Return a list containing the outputs of all get operations in order.
Example 1
operations = [["set", "/users", "A", 1], ["get", "/users", 2], ["get", "/users", 5]], ttl = 3["A", "MISS"]Example 2
operations = [["set", "/feed", "X", 10], ["invalidate", "/feed", 11], ["get", "/feed", 12]], ttl = 5["MISS"]1 <= len(operations) <= 10^51 <= ttl <= 10^9operations = [["set", "/users", "A", 1], ["get", "/users", 2], ["get", "/users", 5]], ttl = 3Output["A", "MISS"]WhyThe entry set at time 1 is still valid at time 2, but at time 5 its age is 4, which is not less than the TTL.operations = [["set", "/feed", "X", 10], ["invalidate", "/feed", 11], ["get", "/feed", 12]], ttl = 5Output["MISS"]WhyThe key is removed before the read, so the cache no longer contains a valid response.operations = [["set", "/posts", "P1", 3], ["set", "/posts", "P2", 4], ["get", "/posts", 5]], ttl = 10Output["P2"]WhyThe second set overwrites the earlier value, so the most recent cached response is returned.1 <= len(operations) <= 10^51 <= ttl <= 10^9Each key and value is a non-empty stringTimestamps are non-negative integersOperations are processed in the given orderdef process_api_cache(operations, ttl):