2025-02-12 21:35:51 +01:00
|
|
|
"""Settings for caching.
|
|
|
|
|
|
|
|
|
|
Kept in an extra module to avoid cyclic dependencies on package import.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
from pathlib import Path
|
|
|
|
|
from typing import Optional
|
|
|
|
|
|
|
|
|
|
from pydantic import Field
|
|
|
|
|
|
|
|
|
|
from akkudoktoreos.config.configabc import SettingsBaseModel
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class CacheCommonSettings(SettingsBaseModel):
|
|
|
|
|
"""Cache Configuration."""
|
|
|
|
|
|
|
|
|
|
subpath: Optional[Path] = Field(
|
2025-11-10 16:57:44 +01:00
|
|
|
default="cache",
|
|
|
|
|
json_schema_extra={"description": "Sub-path for the EOS cache data directory."},
|
2025-02-12 21:35:51 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
cleanup_interval: float = Field(
|
2026-02-22 14:12:42 +01:00
|
|
|
default=5.0 * 60,
|
|
|
|
|
ge=5.0,
|
2025-11-10 16:57:44 +01:00
|
|
|
json_schema_extra={"description": "Intervall in seconds for EOS file cache cleanup."},
|
2025-02-12 21:35:51 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# Do not make this a pydantic computed field. The pydantic model must be fully initialized
|
|
|
|
|
# to have access to config.general, which may not be the case if it is a computed field.
|
|
|
|
|
def path(self) -> Optional[Path]:
|
2025-12-30 22:08:21 +01:00
|
|
|
"""Computed cache path based on general.data_folder_path."""
|
|
|
|
|
if self.config.general.home_assistant_addon:
|
|
|
|
|
# Only /data is persistent for home assistant add-on
|
|
|
|
|
return Path("/data/cache")
|
2025-02-12 21:35:51 +01:00
|
|
|
data_cache_path = self.config.general.data_folder_path
|
|
|
|
|
if data_cache_path is None or self.subpath is None:
|
|
|
|
|
return None
|
|
|
|
|
return data_cache_path.joinpath(self.subpath)
|