caching#
- class pythonning.caching.FilesCache(unique_name: str, location: Path | None = None)#
Bases:
object
Create a cache to store single files, that can be shared across python sessions.
The lifetime of the cache is not guarantee as it is stored in the system temporary location which might be wiped-out independently.
- Parameters:
unique_name – it is recommended to have a name unique across all the infrastructure, but not mandatory as the unique_id delivered by file is more important ot avoid collisions.
location – filesystem path to an existing directory. By default in the system default temporary location, but you can provide you own.
- __init__(unique_name: str, location: Path | None = None)#
- cache_file(file_path: Path, unique_id: str, copy_function: Callable[[Path, Path], None] | None = None) Path #
- Parameters:
file_path – filesystem path to an existing file to cache
unique_id – unique identifier to characterize the file to cache and allow to retrieve a cache given a similar unique_id
copy_function – An optional function that must be called to create the cache. Signature is expected as (“src file”, “target file path destination”) -> None. If not provided
shutil.copy2()
is being used.
- Returns:
filesystem path to the cached file
- clear()#
Delete all the file cached.
- property exists: bool#
- get_file_cache(unique_id: str) Path | None #
Get the potential cache file for the corresponding identifier.
- Parameters:
unique_id – unique identifier characterizing the cached filed
- Returns:
filesystem path to an existing file or None if no cache found.
- property is_empty: bool#