Skip to content

Instantly share code, notes, and snippets.

@mosquito
Last active November 2, 2023 13:48

Revisions

  1. mosquito revised this gist Nov 2, 2023. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion cache_dir.py
    Original file line number Diff line number Diff line change
    @@ -14,7 +14,7 @@


    def get_cache_dir(*suffix) -> Path:
    cache_path = CACHE_PATH.expanduser().expanduser().resolve()
    cache_path = CACHE_PATH.expanduser().resolve()
    if suffix:
    cache_path = cache_path.joinpath(*suffix)
    cache_path.mkdir(exist_ok=True, parents=True)
  2. mosquito created this gist Nov 2, 2023.
    21 changes: 21 additions & 0 deletions cache_dir.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    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().expanduser().resolve()
    if suffix:
    cache_path = cache_path.joinpath(*suffix)
    cache_path.mkdir(exist_ok=True, parents=True)
    return cache_path