def METHOD_NAME(original_func):
    """
    Cache returned value of function in a function. Useful when calling functions
    recursively, especially in dynamic programming where lots of returned values
    can be reused.
    """
    cache = {}
    def new_func(*args):
        h = hashlib.sha1(str(original_func.__name__) + str(args)).hexdigest()
        if h not in cache:
            cache[h] = original_func(*args)
        return cache[h]
    return new_func