cache: add tier definitions and EngineTier function
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
baf98ca80e
commit
ff4149ecbd
2 changed files with 89 additions and 0 deletions
56
internal/cache/tiers.go
vendored
Normal file
56
internal/cache/tiers.go
vendored
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
package cache
|
||||
|
||||
import "time"
|
||||
|
||||
// TTLTier represents a cache TTL tier with a name and duration.
|
||||
type TTLTier struct {
|
||||
Name string
|
||||
Duration time.Duration
|
||||
}
|
||||
|
||||
// defaultTiers maps engine names to their default TTL tiers.
|
||||
var defaultTiers = map[string]TTLTier{
|
||||
// Static knowledge engines — rarely change
|
||||
"wikipedia": {Name: "static", Duration: 24 * time.Hour},
|
||||
"wikidata": {Name: "static", Duration: 24 * time.Hour},
|
||||
"arxiv": {Name: "static", Duration: 24 * time.Hour},
|
||||
"crossref": {Name: "static", Duration: 24 * time.Hour},
|
||||
"stackoverflow": {Name: "static", Duration: 24 * time.Hour},
|
||||
"github": {Name: "static", Duration: 24 * time.Hour},
|
||||
|
||||
// API-based general search — fresher data
|
||||
"braveapi": {Name: "api_general", Duration: 1 * time.Hour},
|
||||
"youtube": {Name: "api_general", Duration: 1 * time.Hour},
|
||||
|
||||
// Scraped general search — moderately stable
|
||||
"google": {Name: "scraped_general", Duration: 2 * time.Hour},
|
||||
"bing": {Name: "scraped_general", Duration: 2 * time.Hour},
|
||||
"duckduckgo": {Name: "scraped_general", Duration: 2 * time.Hour},
|
||||
"qwant": {Name: "scraped_general", Duration: 2 * time.Hour},
|
||||
"brave": {Name: "scraped_general", Duration: 2 * time.Hour},
|
||||
|
||||
// News/social — changes frequently
|
||||
"reddit": {Name: "news_social", Duration: 30 * time.Minute},
|
||||
|
||||
// Image search
|
||||
"bing_images": {Name: "images", Duration: 1 * time.Hour},
|
||||
"ddg_images": {Name: "images", Duration: 1 * time.Hour},
|
||||
"qwant_images": {Name: "images", Duration: 1 * time.Hour},
|
||||
}
|
||||
|
||||
// EngineTier returns the TTL tier for an engine, applying overrides if provided.
|
||||
// If the engine has no defined tier, returns a default of 1 hour.
|
||||
func EngineTier(engineName string, overrides map[string]time.Duration) TTLTier {
|
||||
// Check override first — override tier name is just the engine name
|
||||
if override, ok := overrides[engineName]; ok && override > 0 {
|
||||
return TTLTier{Name: engineName, Duration: override}
|
||||
}
|
||||
|
||||
// Fall back to default tier
|
||||
if tier, ok := defaultTiers[engineName]; ok {
|
||||
return tier
|
||||
}
|
||||
|
||||
// Unknown engines get a sensible default
|
||||
return TTLTier{Name: "unknown", Duration: 1 * time.Hour}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue