MCPcopy
hub / github.com/omkarcloud/botasaurus / _get_cache_path

Function _get_cache_path

botasaurus/cache.py:33–48  ·  view source on GitHub ↗
(func, data)

Source from the content-addressed store, hash-verified

31 return func if isinstance(func, str) else func.__name__
32
33def _get_cache_path(func, data):
34 fn_name = getfnname(func)
35 fn_cache_dir = f'{Cache.cache_directory}{fn_name}/'
36
37 # Serialize the data to a JSON string and encode to bytes
38 serialized_data = json.dumps(data).encode('utf-8')
39
40 # Generate a hash from the serialized data
41 data_hash = md5(serialized_data).hexdigest()
42 if Cache.cache_directory == "cache/":
43 cache_path = os.path.join(fn_cache_dir, data_hash + ".json")
44 else:
45 cache_path = os.path.join(relative_path(fn_cache_dir), data_hash + ".json")
46 # Create a unique cache file path with a .json extension
47 cache_path = os.path.join(fn_cache_dir, data_hash + ".json")
48 return cache_path
49
50def _hash( data):
51 # Serialize the data to a JSON string and encode to bytes

Callers 6

getMethod · 0.85
putMethod · 0.85
hasMethod · 0.85
getMethod · 0.85
deleteMethod · 0.85

Calls 3

getfnnameFunction · 0.85
joinMethod · 0.80
relative_pathFunction · 0.70

Tested by

no test coverage detected