set_temp_cache#
- class astropy.config.set_temp_cache(path=None, delete=False)[source]#
Bases:
_SetTempPathContext manager to set a temporary path for the Astropy download cache, primarily for use with testing (though there may be other applications for setting a different cache directory, for example to switch to a cache dedicated to large files).
If the path set by this context manager does not already exist it will be created, if possible.
This may also be used as a decorator on a function to set the cache path just within that function.
Thread safety is guaranteed since astropy 7.2.1, but concurrency isn’t: only a single thread at a time may execute code within this context.
Changed in version 8.0: This function is soft-deprecated. It won’t emit deprecation warnings but its use is discouraged for new code, as the exact behavior is hard to predict. Prefer
temporary_cache_dir_path()where available.- Parameters:
- path
python:str The directory (which must exist) in which to find the Astropy cache files, or create them if they do not already exist. If None, this restores the cache path to the user’s default cache path as returned by
get_cache_diras though this context manager were not in effect (this is useful for testing). In this case thedeleteargument is always ignored.- deletebool, optional
If True, cleans up the temporary directory after exiting the temp context (default: False).
- path
See also
temporary_cache_dir_patha function with similar goals but a much more predictable behavior