From d982eb2d1161b406328f280aa11dcfb27cf517bd Mon Sep 17 00:00:00 2001 From: Bas des Tombe Date: Wed, 18 Dec 2024 13:00:13 +0100 Subject: [PATCH] [cache] Use hashlib instead of dask tokenize to validate cached file on disk (#395) --- nlmod/cache.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/nlmod/cache.py b/nlmod/cache.py index 0ed0d441..b0df148c 100644 --- a/nlmod/cache.py +++ b/nlmod/cache.py @@ -1,4 +1,5 @@ import functools +import hashlib import importlib import inspect import logging @@ -208,7 +209,8 @@ def wrapper(*args, cachedir=None, cachename=None, **kwargs): if pickle_check: # Ensure that the pickle pairs with the netcdf, see #66. - func_args_dic["_nc_hash"] = dask.base.tokenize(cached_ds) + cache_bytes = open(fname_cache, 'rb').read() + func_args_dic["_nc_hash"] = hashlib.sha256(cache_bytes).hexdigest() if dataset is not None: # Check the coords of the dataset argument @@ -261,8 +263,8 @@ def wrapper(*args, cachedir=None, cachename=None, **kwargs): result.to_netcdf(fname_cache) # add netcdf hash to function arguments dic, see #66 - with xr.open_dataset(fname_cache) as temp: - func_args_dic["_nc_hash"] = dask.base.tokenize(temp) + cache_bytes = open(fname_cache, 'rb').read() + func_args_dic["_nc_hash"] = hashlib.sha256(cache_bytes).hexdigest() # Add dataset argument hash to pickle if dataset is not None: