首尔/釜山 AMOS 数据缓存 TTL 从 300s 降至 60s,对齐官网 1 分钟刷新频率

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
AmandaloveYang
2026-05-11 17:28:53 +08:00
co-authored by Claude Opus 4.7
parent 52ad2dfde4
commit e344fae75f
3 changed files with 12 additions and 4 deletions
@@ -333,8 +333,6 @@ def _amos_parse_runway_table(text: str) -> dict[str, Any]:
class AmosStationSourceMixin: class AmosStationSourceMixin:
"""Mixin that adds AMOS runway-level data fetching to WeatherDataCollector.""" """Mixin that adds AMOS runway-level data fetching to WeatherDataCollector."""
amos_cache_ttl_sec: int = 300 # 5 minutes
def _amos_get_page(self, icao: str) -> Optional[str]: def _amos_get_page(self, icao: str) -> Optional[str]:
"""Fetch the AMOS page. """Fetch the AMOS page.
+11 -2
View File
@@ -18,6 +18,7 @@ from web.core import (
_cache, _cache,
CACHE_TTL, CACHE_TTL,
CACHE_TTL_ANKARA, CACHE_TTL_ANKARA,
CACHE_TTL_KOREAN_AMOS,
CITIES, CITIES,
CITY_RISK_PROFILES, CITY_RISK_PROFILES,
SETTLEMENT_SOURCE_LABELS, SETTLEMENT_SOURCE_LABELS,
@@ -177,8 +178,16 @@ def get_analysis_cache_stats() -> Dict[str, Any]:
return stats return stats
KOREAN_AMOS_CITIES = {"seoul", "busan"}
def _analysis_ttl_for_city(city: str) -> int: def _analysis_ttl_for_city(city: str) -> int:
return CACHE_TTL_ANKARA if city.lower() in TURKISH_MGM_CITIES else CACHE_TTL city_lower = city.lower()
if city_lower in TURKISH_MGM_CITIES:
return CACHE_TTL_ANKARA
if city_lower in KOREAN_AMOS_CITIES:
return CACHE_TTL_KOREAN_AMOS
return CACHE_TTL
def _analysis_cache_key(city: str, detail_mode: str = "full") -> str: def _analysis_cache_key(city: str, detail_mode: str = "full") -> str:
@@ -1617,7 +1626,7 @@ def _analyze(
) -> Dict[str, Any]: ) -> Dict[str, Any]:
"""Fetch, analyse, and return structured weather data for one city.""" """Fetch, analyse, and return structured weather data for one city."""
# Check cache # Check cache
ttl = CACHE_TTL_ANKARA if city.lower() in TURKISH_MGM_CITIES else CACHE_TTL ttl = _analysis_ttl_for_city(city)
normalized_detail_mode_raw = str(detail_mode or "full").strip().lower() normalized_detail_mode_raw = str(detail_mode or "full").strip().lower()
if normalized_detail_mode_raw == "panel": if normalized_detail_mode_raw == "panel":
normalized_detail_mode = "panel" normalized_detail_mode = "panel"
+1
View File
@@ -86,6 +86,7 @@ SETTLEMENT_SOURCE_LABELS: Dict[str, str] = {
_cache: Dict[str, Dict] = {} _cache: Dict[str, Dict] = {}
CACHE_TTL = 300 CACHE_TTL = 300
CACHE_TTL_ANKARA = 60 CACHE_TTL_ANKARA = 60
CACHE_TTL_KOREAN_AMOS = 60
_PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) _PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
_PROBABILITY_EVALUATION_REPORT = os.path.join( _PROBABILITY_EVALUATION_REPORT = os.path.join(
_PROJECT_ROOT, _PROJECT_ROOT,