def METHOD_NAME(fn):
    class cache(dict):
        def __missing__(self, key):
            value = fn(key)
            self[key] = value
            return value
    c = cache()
    # more helpful debugging wrapper
    @functools.wraps(fn)
    def wrapper(key):
        return c.__getitem__(key)
    return wrapper