Skip to content

Instantly share code, notes, and snippets.

@mosquito
Last active November 2, 2023 13:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mosquito/97235ec096bd91263a3090456e43f16b to your computer and use it in GitHub Desktop.
Save mosquito/97235ec096bd91263a3090456e43f16b to your computer and use it in GitHub Desktop.
import platform
from pathlib import Path
match platform.system():
case 'Linux':
CACHE_PATH = Path(os.getenv("XDG_CACHE_HOME", '~/.cache'))
case 'Darwin':
CACHE_PATH = Path('~') / 'Library' / 'Caches'
case 'Windows':
CACHE_PATH = Path('~') / 'AppData' / 'Local'
case _:
CACHE_PATH = Path(tempfile.gettempdir()) / "cache"
def get_cache_dir(*suffix) -> Path:
cache_path = CACHE_PATH.expanduser().resolve()
if suffix:
cache_path = cache_path.joinpath(*suffix)
cache_path.mkdir(exist_ok=True, parents=True)
return cache_path
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment