Skip to content

Commit

Permalink
Include args in the cache name as a sha code (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
louisPoulain authored Oct 24, 2024
1 parent c83d999 commit 26337bd
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion mlpp_features/decorators.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import hashlib
import logging
import os
import pickle
Expand Down Expand Up @@ -80,7 +81,9 @@ def cache(fn):
def inner(*args, **kwargs):
if CACHEDIR_PREFIX is None:
return fn(*args, **kwargs)
cachedfile = Path(CACHEDIR.name) / f"{fn.__name__}.pkl"
hash_object = hashlib.sha256(",".join(map(str, args)).encode())
hash_hex = hash_object.hexdigest()
cachedfile = Path(CACHEDIR.name) / f"{fn.__name__}_{hash_hex}.pkl"
if not cachedfile.is_file():
out = fn(*args, **kwargs).compute()
LOGGER.debug(f"to cache: {cachedfile}")
Expand Down

0 comments on commit 26337bd

Please sign in to comment.