23def get_cache_dir(cache_dir: Optional[str] = None) -> str:
24 """
25 Returns a default directory to cache static files
26 (usually downloaded from Internet), if None is provided.
27 Args:
28 cache_dir (None or str): if not None, will be returned as is.
29 If None, returns the default cache directory as:
30 1) $FVCORE_CACHE, if set
31 2) otherwise ~/.torch/fvcore_cache
32 """
33 if cache_dir is None:
34 cache_dir = os.path.expanduser(
35 os.getenv("FVCORE_CACHE", "~/.torch/fvcore_cache")
36 )
37 return cache_dir
38
39