from spotforecast2_safe.data.fetch_data import get_cache_home
cache_dir = get_cache_home()
print(cache_dir.name)
print(cache_dir.parent.name).spotforecast2_cache
runner
Return the location where persistent models are to be cached.
By default the cache directory is set to a folder named .spotforecast2_cache in the user home folder. Alternatively, it can be set by the SPOTFORECAST2_CACHE environment variable or programmatically by giving an explicit folder path. The ~ symbol is expanded to the user home folder. When create_dir is True (the default) the directory is created automatically if it does not already exist.
This directory is used to store pickled trained models for quick reuse across forecasting runs, following scikit-learn model persistence conventions.
| Name | Type | Description | Default |
|---|---|---|---|
| cache_home | Optional[Union[str, Path]] | Path to the spotforecast cache directory. If None, the value of the SPOTFORECAST2_CACHE environment variable is used when set, otherwise the default path ~/.spotforecast2_cache is used. |
None |
| create_dir | bool | Whether to create the cache directory if it does not exist. When True (the default), the directory and any missing parent directories are created automatically. When False, the resolved path is returned without touching the filesystem. |
True |
| Name | Type | Description |
|---|---|---|
| Path | Absolute path to the spotforecast cache directory. |
| Name | Type | Description |
|---|---|---|
| OSError | If create_dir is True and the directory cannot be created due to a permissions error or other OS-level failure. |
from spotforecast2_safe.data.fetch_data import get_cache_home
cache_dir = get_cache_home()
print(cache_dir.name)
print(cache_dir.parent.name).spotforecast2_cache
runner
# Using custom path
from spotforecast2_safe.data.fetch_data import get_cache_home
from pathlib import Path
import tempfile
with tempfile.TemporaryDirectory() as tmp:
custom_cache = get_cache_home(Path(tmp) / 'my_cache')
print(custom_cache.exists())True