(func)
return wrapper
Thread-safe caching.
Thread-safe caching.
Thread - safe caching .
def cache(func):
    """Thread-safe caching."""
    lock = threading.Lock()
    results = {}

    def wrapper(*args, **kwargs):
        identifier = checksum(args, kwargs)
        if identifier in results:
            return results[identifier]
        with lock:
            if identifier in results:
                return results[identifier]
            result = func(*args, **kwargs)
            results[identifier] = result
            return result

    return wrapper
def cache ( func ) : lock = threading . Lock ( ) results = { } def wrapper ( * args , * * kwargs ) : identifier = checksum ( args , kwargs ) if identifier in results : return results [ identifier ] with lock : if identifier in results : return results [ identifier ] result = func ( * args , * * kwargs ) results [ identifier ] = result return result return wrapper