diff --git a/pytools/persistent_dict.py b/pytools/persistent_dict.py index 4e6d64cb..6d3fa5eb 100644 --- a/pytools/persistent_dict.py +++ b/pytools/persistent_dict.py @@ -565,7 +565,7 @@ def __init__(self, identifier, key_builder=None, container_dir=None): container_dir = join( cache_dir, - "pdict-v4-{}-py{}".format( + "pdict-v5-{}-py{}".format( identifier, ".".join(str(i) for i in sys.version_info))) @@ -589,14 +589,20 @@ def fetch(self, key, _stacklevel=0): @staticmethod def _read(path): + import lzma from pickle import load - with open(path, "rb") as inf: - return load(inf) + try: + with lzma.open(path, "rb") as inf: + return load(inf) + except lzma.LZMAError: + with open(path, "rb") as inf: + return load(inf) @staticmethod def _write(path, value): + import lzma from pickle import HIGHEST_PROTOCOL, dump - with open(path, "wb") as outf: + with lzma.open(path, "wb") as outf: dump(value, outf, protocol=HIGHEST_PROTOCOL) def _item_dir(self, hexdigest_key): @@ -607,9 +613,8 @@ def _item_dir(self, hexdigest_key): # This doesn't solve that problem, but it makes it much less likely return join(self.container_dir, - hexdigest_key[:3], - hexdigest_key[3:6], - hexdigest_key[6:]) + hexdigest_key[:1], + hexdigest_key[1:]) def _key_file(self, hexdigest_key): from os.path import join