fsspec/implementations/cached.py
def save_cache(self):
        """Save set of stored blocks from file"""
        fn = os.path.join(self.storage[-1], "cache")
        # TODO: a file lock could be used to ensure file does not change
        #  between re-read and write; but occasional duplicated reads ok.
        cache = self.cached_files[-1]
        if os.path.exists(fn):
            with open(fn, "rb") as f:
                cached_files = pickle.load(f)
            for k, c in cached_files.items():
                if k in cache:
                    if c["blocks"] is True or cache[k]["blocks"] is True:
                        c["blocks"] = True
                    else:
                        c["blocks"] = set(c["blocks"]).union(cache[k]["blocks"])
                    c["time"] = max(c["time"], cache[k]["time"])
                    c["uid"] = cache[k]["uid"]

            # Files can be added to cache after it was written once
            for k, c in cache.items():
                if k not in cached_files:
                    cached_files[k] = c
        else:
            cached_files = cache
        cache = {k: v.copy() for k, v in cached_files.items()}
        for c in cache.values():
            if isinstance(c["blocks"], set):
                c["blocks"] = list(c["blocks"])
        fn2 = tempfile.mktemp()
        with open(fn2, "wb") as f:
            pickle.dump(cache, f)
        self._mkcache()
        move(fn2, fn)
        self.cached_files[-1] = cached_files
        self.last_cache = time.time()
Save set of stored blocks from file
Save set of stored blocks from file
Save set of stored blocks from file
def save_cache(self):
        fn = os.path.join(self.storage[-1], "cache")
        cache = self.cached_files[-1]
        if os.path.exists(fn):
            with open(fn, "rb") as f:
                cached_files = pickle.load(f)
            for k, c in cached_files.items():
                if k in cache:
                    if c["blocks"] is True or cache[k]["blocks"] is True:
                        c["blocks"] = True
                    else:
                        c["blocks"] = set(c["blocks"]).union(cache[k]["blocks"])
                    c["time"] = max(c["time"], cache[k]["time"])
                    c["uid"] = cache[k]["uid"]
            for k, c in cache.items():
                if k not in cached_files:
                    cached_files[k] = c
        else:
            cached_files = cache
        cache = {k: v.copy() for k, v in cached_files.items()}
        for c in cache.values():
            if isinstance(c["blocks"], set):
                c["blocks"] = list(c["blocks"])
        fn2 = tempfile.mktemp()
        with open(fn2, "wb") as f:
            pickle.dump(cache, f)
        self._mkcache()
        move(fn2, fn)
        self.cached_files[-1] = cached_files
        self.last_cache = time.time()
def save_cache ( self ) : fn = os . path . join ( self . storage [ - 1 ] , "cache" ) cache = self . cached_files [ - 1 ] if os . path . exists ( fn ) : with open ( fn , "rb" ) as f : cached_files = pickle . load ( f ) for k , c in cached_files . items ( ) : if k in cache : if c [ "blocks" ] is True or cache [ k ] [ "blocks" ] is True : c [ "blocks" ] = True else : c [ "blocks" ] = set ( c [ "blocks" ] ) . union ( cache [ k ] [ "blocks" ] ) c [ "time" ] = max ( c [ "time" ] , cache [ k ] [ "time" ] ) c [ "uid" ] = cache [ k ] [ "uid" ] for k , c in cache . items ( ) : if k not in cached_files : cached_files [ k ] = c else : cached_files = cache cache = { k : v . copy ( ) for k , v in cached_files . items ( ) } for c in cache . values ( ) : if isinstance ( c [ "blocks" ] , set ) : c [ "blocks" ] = list ( c [ "blocks" ] ) fn2 = tempfile . mktemp ( ) with open ( fn2 , "wb" ) as f : pickle . dump ( cache , f ) self . _mkcache ( ) move ( fn2 , fn ) self . cached_files [ - 1 ] = cached_files self . last_cache = time . time ( )
Save set of stored blocks from file
Save set of stored blocks from file
"""Save set of stored blocks from file""" # TODO: a file lock could be used to ensure file does not change #  between re-read and write; but occasional duplicated reads ok. # Files can be added to cache after it was written once
self