-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrefresh_cache.py
More file actions
32 lines (25 loc) · 984 Bytes
/
refresh_cache.py
File metadata and controls
32 lines (25 loc) · 984 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from logger import setup_logger
import os
import shutil
from pathlib import Path
from typing import Optional
logger = setup_logger("cache-refresh-subroutine")
logger.setLevel("INFO")
# Default to project directory to avoid home disk quota issues
_PROJECT_ROOT = Path(__file__).parent.resolve()
_DEFAULT_CACHE_BASE = _PROJECT_ROOT / ".cache"
def refresh_cache(base_dir: Optional[str] = None):
"""Clear and recreate PyStan/httpstan cache directory.
If base_dir is None, uses the project .cache directory (not home).
"""
if base_dir:
cache_path = os.path.join(base_dir, "httpstan")
else:
cache_path = str(_DEFAULT_CACHE_BASE / "httpstan")
logger.info(f"Refreshing cache at {cache_path}")
if os.path.exists(cache_path):
logger.info(f"Removing {cache_path}")
shutil.rmtree(cache_path)
logger.info(f"Creating {cache_path}")
os.makedirs(cache_path, exist_ok=True)
logger.success("Successfully refreshed cache.")