Practice #2
Lesson 9 of 12 in Coddy's Python Decorators course.
Challenge
MediumWrite a decorator named cache_decorator that caches the return value of a function. The decorator should maintain a dictionary mapping input arguments to return values and check the dictionary before executing the function to see if the value has already been computed. If the value is in the cache, the decorator should return it immediately without executing the function. If the value is not in the cache, the decorator should execute the function and add the result to the cache before returning it.
Try it yourself