(func)
return _cached
Cache with size 1.
Cache with size 1.
Cache with size 1 .
def single_cache(func):
    """Cache with size 1."""
    last_args = ()
    last_kwargs = set()
    last_result = None

    @wraps(func)
    def _cached(*args, **kwargs):
        nonlocal last_args, last_kwargs, last_result
        if len(last_args) != len(args) or \
                not all(x is y for x, y in zip(args, last_args)) or \
                last_kwargs != set(kwargs) or \
                any(last_kwargs[k] != kwargs[k] for k in last_kwargs):
            last_result = func(*args, **kwargs)
            last_args, last_kwargs = args, kwargs
        return last_result

    return _cached
def single_cache ( func ) : last_args = ( ) last_kwargs = set ( ) last_result = None @ wraps ( func ) def _cached ( * args , * * kwargs ) : nonlocal last_args , last_kwargs , last_result if len ( last_args ) != len ( args ) or not all ( x is y for x , y in zip ( args , last_args ) ) or last_kwargs != set ( kwargs ) or any ( last_kwargs [ k ] != kwargs [ k ] for k in last_kwargs ) : last_result = func ( * args , * * kwargs ) last_args , last_kwargs = args , kwargs return last_result return _cached