xrheed.kinematics.cache_utils
Functions
|
Decorator for class methods that provides persistent, file-based caching. |
- smart_cache(method)[source]
Decorator for class methods that provides persistent, file-based caching.
Expected instance attributes
- use_cachebool
Enables caching when True. If False, the method always computes the result without reading or writing cache files.
- cache_dirstr
Directory where cache files are stored. Must be a string path. The directory will be created automatically if it does not exist.
- cache_keystr or None
Optional suffix appended to cache filenames. Allows distinguishing cache files for different runs or configurations of the same method.
Caching behavior
- If use_cache is False:
The method executes normally (no reads/writes).
- If use_cache is True:
- The decorator builds a deterministic filename:
cache_<method>[_<cache_key>].dill
and stores it inside cache_dir.
If the file exists, the cached result is returned. Otherwise, the method is executed and the result is written to disk.
Notes
Method arguments are NOT included or hashed into the cache filename.
Cached results use dill for full Python object serialization.