diff --git a/internal/config/config.go b/internal/config/config.go index 6158af7..c834016 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -63,10 +63,11 @@ type StackOverflowConfig struct { // CacheConfig holds Valkey/Redis cache settings. type CacheConfig struct { - Address string `toml:"address"` // Valkey server address (e.g. "localhost:6379") - Password string `toml:"password"` // Auth password (empty = none) - DB int `toml:"db"` // Database index (default 0) - DefaultTTL string `toml:"default_ttl"` // Cache TTL (e.g. "5m", default "5m") + Address string `toml:"address"` // Valkey server address (e.g. "localhost:6379") + Password string `toml:"password"` // Auth password (empty = none) + DB int `toml:"db"` // Database index (default 0) + DefaultTTL string `toml:"default_ttl"` // Cache TTL (e.g. "5m", default "5m") + TTLOverrides map[string]string `toml:"ttl_overrides"` // engine -> duration string } // CORSConfig holds CORS middleware settings. @@ -284,6 +285,20 @@ func (c *Config) CacheTTL() time.Duration { return 5 * time.Minute } +// CacheTTLOverrides returns parsed TTL overrides from config. +func (c *Config) CacheTTLOverrides() map[string]time.Duration { + if len(c.Cache.TTLOverrides) == 0 { + return nil + } + out := make(map[string]time.Duration, len(c.Cache.TTLOverrides)) + for engine, durStr := range c.Cache.TTLOverrides { + if d, err := time.ParseDuration(durStr); err == nil && d > 0 { + out[engine] = d + } + } + return out +} + // RateLimitWindow parses the rate limit window into a time.Duration. func (c *Config) RateLimitWindow() time.Duration { if d, err := time.ParseDuration(c.RateLimit.Window); err == nil && d > 0 {