From eba9fa1be0ddd7234ace70924bc96e14572ded08 Mon Sep 17 00:00:00 2001 From: Rogee Date: Wed, 29 Jul 2026 17:54:15 +0800 Subject: [PATCH] fix: egress cache TTL independent from fetcher cache (24h default) Egress probe results (IP/country/region/city/isp) were cached using the fetcher's cache_ttl (300s / 5min). After 5 minutes the cache expired and the node list showed empty Egress IP/Country/Region fields again. Add a dedicated egress_cache_ttl config (default 24h) so egress data persists long enough to be useful when re-expanding the node list. --- config/config.example.yaml | 1 + internal/config/config.go | 2 ++ internal/handler/egress_info.go | 4 ++-- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/config/config.example.yaml b/config/config.example.yaml index cfb3e02..5002894 100644 --- a/config/config.example.yaml +++ b/config/config.example.yaml @@ -25,6 +25,7 @@ fetcher: max_response_bytes: 2097152 # 2 MiB max_total_bytes: 12582912 # 12 MiB proxy_url: "" # e.g. "http://127.0.0.1:7890" for fetching sources behind Cloudflare + egress_cache_ttl: 24h # TTL for egress IP/country/region probe cache recycle: max_entries: 50 diff --git a/internal/config/config.go b/internal/config/config.go index 52faa30..353aee1 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -47,6 +47,7 @@ type FetcherConfig struct { MaxResponseBytes int `mapstructure:"max_response_bytes"` MaxTotalBytes int `mapstructure:"max_total_bytes"` ProxyURL string `mapstructure:"proxy_url"` + EgressCacheTTL time.Duration `mapstructure:"egress_cache_ttl"` } type RecycleConfig struct { @@ -80,6 +81,7 @@ func defaults() { viper.SetDefault("fetcher.max_response_bytes", 2*1024*1024) viper.SetDefault("fetcher.max_total_bytes", 12*1024*1024) viper.SetDefault("fetcher.proxy_url", "") + viper.SetDefault("fetcher.egress_cache_ttl", 24*time.Hour) viper.SetDefault("recycle.max_entries", 50) viper.SetDefault("app.name", "Sub-Store") viper.SetDefault("app.version", "1.0.0") diff --git a/internal/handler/egress_info.go b/internal/handler/egress_info.go index 14d109b..51e7514 100644 --- a/internal/handler/egress_info.go +++ b/internal/handler/egress_info.go @@ -66,9 +66,9 @@ func (d *Deps) HandleEgressInfo(c fiber.Ctx) error { } info["cached"] = false if data, err := json.Marshal(info); err == nil { - ttl := int(d.Cfg.Fetcher.CacheTTL.Seconds()) + ttl := int(d.Cfg.Fetcher.EgressCacheTTL.Seconds()) if ttl <= 0 { - ttl = 300 + ttl = 86400 // 24h default } d.CacheRepo.SafePut(cacheKey, string(data), nil, ttl) }