Skip to content

Commit

Permalink
[cache] Use hashlib instead of dask tokenize to validate cached file …
Browse files Browse the repository at this point in the history
…on disk
  • Loading branch information
bdestombe committed Dec 18, 2024
1 parent e6d7df8 commit 8fe6b07
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions nlmod/cache.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import functools
import hashlib
import importlib
import inspect
import logging
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 8fe6b07

Please sign in to comment.