mirror of
https://github.com/wassname/cachier.git
synced 2026-09-09 11:19:08 +08:00
make every argument hached
This commit is contained in:
+26
-2
@@ -152,10 +152,34 @@ class _PickleCore(_BaseCore):
|
||||
return key, self._get_cache().get(key, None)
|
||||
|
||||
def get_entry(self, args, kwds):
|
||||
key = args + tuple(sorted(kwds.items()))
|
||||
# print('key type={}, key={}'.format(type(key), key))
|
||||
key = tuple(self.hash_args(key) for key in args + tuple(sorted(kwds.items())))
|
||||
return self.get_entry_by_key(key)
|
||||
|
||||
def hash_args(self, value):
|
||||
try:
|
||||
import pandas
|
||||
if isinstance(value, pandas.DataFrame):
|
||||
return(pandas.util.hash_pandas_object(value))
|
||||
except ImportError:
|
||||
pass
|
||||
if hasattr(value, "to_bytes"): # For numpy
|
||||
try:
|
||||
return hash(value.to_bytes())
|
||||
except TypeError:
|
||||
pass
|
||||
elif hasattr(value, "__iter__"): # For iterators
|
||||
hash_array = []
|
||||
for elem in value:
|
||||
hash_array.append(value)
|
||||
return tuple(hash_array)
|
||||
elif hasattr(value, "items"): # For dict
|
||||
hash_array = []
|
||||
for key, elem in value.items:
|
||||
hash_array.append(key)
|
||||
hash_array.append(elem)
|
||||
return tuple(hash_array)
|
||||
return hash(value)
|
||||
|
||||
def set_entry(self, key, func_res):
|
||||
with self.lock:
|
||||
cache = self._get_cache()
|
||||
|
||||
Reference in New Issue
Block a user