Volvo CarsEasyPython00:00

Welcome to the Python screen for the Mobile Engineer role at Volvo Cars.
The question is on your right: Build Mobile API Request Cache. Read through the requirements first.
Would you like to talk through your approach, or are you ready to start coding?
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.
def process_api_cache(operations, ttl):