human
Solve the following python programming problem given the following code:
@public
def cache_value(duration=None):
assistant
#Here is the Python program you requested.

    """Makes a function lazy.
    :param duration: cache duration in seconds (default: infinite)
    :type  duration: int
    """
    def decorator(fx):
        fx.__cached = None
        fx.__cached_at = 0
        def wrapper(*args, **kwargs):
            dt = (time.time() - fx.__cached_at)
            if (((dt > duration) and (duration is not None)) or ((fx.__cached_at == 0) and (duration is None))):
                val = fx(*args, **kwargs)
                fx.__cached = val
                fx.__cached_at = time.time()
            else:
                val = fx.__cached
            return val
        wrapper.__doc__ = fx.__doc__
        return wrapper
    return decorator