File tree Expand file tree Collapse file tree 2 files changed +17
-7
lines changed Expand file tree Collapse file tree 2 files changed +17
-7
lines changed Original file line number Diff line number Diff line change 22
33from __future__ import annotations
44
5+ import os
56import ssl
67from os import PathLike
78from pathlib import Path
@@ -385,6 +386,21 @@ def apply_web(config: WebConfig) -> None:
385386 manager .apply_web_env (dict (config .env_vars ))
386387
387388
389+ def _default_cache_directory () -> Path :
390+ """Determine the default on-disk cache directory respecting platform conventions."""
391+
392+ base_override = os .getenv ("TIDY3D_BASE_DIR" )
393+ if base_override :
394+ base = Path (base_override ).expanduser ().resolve () / ".cache"
395+ else :
396+ xdg_cache = os .getenv ("XDG_CACHE_HOME" )
397+ if xdg_cache :
398+ base = Path (xdg_cache ).expanduser ().resolve ()
399+ else :
400+ base = Path .home () / ".cache"
401+ return (base / "tidy3d" / "simulations" ).resolve ()
402+
403+
388404@register_section ("local_cache" )
389405class LocalCacheConfig (ConfigSection ):
390406 """Settings controlling the optional local simulation cache."""
@@ -397,7 +413,7 @@ class LocalCacheConfig(ConfigSection):
397413 )
398414
399415 directory : DirectoryPath = Field (
400- Path . home () / ".tidy3d" / "cache" ,
416+ default_factory = _default_cache_directory ,
401417 title = "Cache directory" ,
402418 description = "Directory where cached artifacts are stored." ,
403419 json_schema_extra = {"persist" : True },
Original file line number Diff line number Diff line change 2222from tidy3d .web .core .constants import TaskId
2323from tidy3d .web .core .http_util import get_version as _get_protocol_version
2424
25- DEFAULT_CACHE_RELATIVE_DIR = Path (".tidy3d" ) / "cache" / "simulations"
2625CACHE_ARTIFACT_NAME = "simulation_data.hdf5"
2726CACHE_METADATA_NAME = "metadata.json"
2827
29- ENV_ENABLE = "TIDY3D_CACHE_ENABLED"
30- ENV_DIRECTORY = "TIDY3D_CACHE_DIR"
31- ENV_MAX_SIZE = "TIDY3D_CACHE_MAX_SIZE_GB"
32- ENV_MAX_ENTRIES = "TIDY3D_CACHE_MAX_ENTRIES"
33-
3428TMP_PREFIX = "tidy3d-cache-"
3529TMP_BATCH_PREFIX = "tmp_batch"
3630
You can’t perform that action at this time.
0 commit comments