import functools


def memoize(cache):
    """Minimal memoization decorator"""
    def decorator(func):
        def wrapper(*args):
            try:
                return cache[args]
            except KeyError:
                pass  # Not found

            result = func(*args)
            cache[args] = result
            return result

        return functools.update_wrapper(wrapper, func)

    return decorator