Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cache] Validate cached file with hashlib instead of dask tokenize #395

Merged
merged 1 commit into from
Dec 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading