[docs]defcache_directory(dir:Optional[str]=None)->str:"""Cache directory. Specify the cache directory in the local filesystem for gypsum-related data. If the ``GYPSUM_CACHE_DIR`` environment variable is set before the first call to ``cache_directory()``, it is used as the initial location of the cache directory. Otherwise, the initial location is set to user's home directory defined by ``appdirs.user_cache_dir()``. Args: dir: Path to the current cache directory. If `None`, a default cache location is chosen. Returns: If ``dir`` is ``None``, the path to the cache directory is returned. If ``dir`` is supplied, it is used to set the path to the cache directory, and the previous location of the directory is returned. """globalCURRENT_CACHE_DIRECTORYifCURRENT_CACHE_DIRECTORYisNone:_from_env=os.environ.get("GYPSUM_CACHE_DIR",None)if_from_envisnotNone:CURRENT_CACHE_DIRECTORY=_from_envelse:importappdirsCURRENT_CACHE_DIRECTORY=appdirs.user_cache_dir("gypsum","ArtifactDB")prev=CURRENT_CACHE_DIRECTORYifdirisnotNone:CURRENT_CACHE_DIRECTORY=dirreturnprev