Sobes.tech
Middle+

Task: write a decorator that caches the result of a function for a specified time (ttl). TTL is set in seconds (int). 1) describe the basic scheme of this code with all possible corner cases. 2) (optional) implement in code import time # implementation pass # print(f"Func in cache: {}") # print(f"Time is valid: {}") @ttl_cache(ttl=1) def multiplier(a, b, **kwargs): return a * b print(f'now={time.time()}') print(f'result={multiplier(5, 5, x=1)}; time={time.time()}') print(f'result={multiplier(5, 5, x=1)}; time={time.time()}') print(f'result={multiplier(2, 5, x=1)}; time={time.time()}') time.sleep(2) print(f'result={multiplier(5, 5, x=1)}; time={time.time()}')