| 31 | return func if isinstance(func, str) else func.__name__ |
| 32 | |
| 33 | def _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 | |
| 50 | def _hash( data): |
| 51 | # Serialize the data to a JSON string and encode to bytes |