config: add TTLOverrides to CacheConfig
This commit is contained in:
parent
e9625441cc
commit
b710aec798
1 changed files with 19 additions and 4 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue