7
7
from pathlib import Path
8
8
from collections .abc import Mapping
9
9
from functools import singledispatch
10
- from hashlib import blake2b
10
+ from hashlib import blake2b , blake2s
11
11
import logging
12
12
from typing import (
13
13
Dict ,
@@ -135,7 +135,7 @@ def get_or_calculate_hash(self, key: CacheKey, calculate_hash: ty.Callable) -> H
135
135
return self ._hashes [key ]
136
136
except KeyError :
137
137
pass
138
- key_path = self .location / blake2b (str (key ).encode ()).hexdigest ()
138
+ key_path = self .location / blake2s (str (key ).encode ()).hexdigest ()
139
139
with SoftFileLock (key_path .with_suffix (".lock" )):
140
140
if key_path .exists ():
141
141
return Hash (key_path .read_bytes ())
@@ -147,6 +147,8 @@ def clean_up(self):
147
147
"""Cleans up old hash caches that haven't been accessed in the last 30 days"""
148
148
now = datetime .now ()
149
149
for path in self .location .iterdir ():
150
+ if path .endswith (".lock" ):
151
+ continue
150
152
days = (now - datetime .fromtimestamp (path .lstat ().st_atime )).days
151
153
if days > self .cleanup_period :
152
154
path .unlink ()
@@ -198,10 +200,10 @@ def hash_object(
198
200
Base Python types are implemented, including recursive lists and
199
201
dicts. Custom types can be registered with :func:`register_serializer`.
200
202
"""
201
- # try:
202
- return hash_single (obj , Cache (persistent = persistent_cache ))
203
- # except Exception as e:
204
- # raise UnhashableError(f"Cannot hash object {obj!r} due to '{e}'") from e
203
+ try :
204
+ return hash_single (obj , Cache (persistent = persistent_cache ))
205
+ except Exception as e :
206
+ raise UnhashableError (f"Cannot hash object { obj !r} due to '{ e } '" ) from e
205
207
206
208
207
209
def hash_single (obj : object , cache : Cache ) -> Hash :
0 commit comments