CachedFile (autotransform.util.cachedfile)
CachedFile is a utility class used by AutoTransform to cache file content on read/write to reduce excessive file reads and speed up processing. The FILE_CACHE variable stores cached file contents, while a CachedFile object is used to interact with the cache. All writes should go through the CachedFile object to ensure the cache is properly updated.
- class autotransform.util.cachedfile.CachedFile(path: str)
Bases:
object
A wrapper that allows accessing cached file contents. Content is stored in the FILE_CACHE variable. Writing files outside the CachedFile write method can lead to invalid cache data.
- path
The path of the file being cached.
- Type:
str
- get_content() str
Gets the file contents from the cache if present. If not present, it will read the file contents and cache it before returning.
- Returns:
The contents of the file represented by this object.
- Return type:
str
- path: str
- revert() None
Reverts the content of a file to its original content.
- write_content(new_content: str) None
Updates the content of a cached file, including writing the file.
- Parameters:
new_content (str) – The content to put in the file.