Commit 47f9490

Eric Bower  ·  2026-04-19 12:02:29 -0400 EDT
parent 4ee7ba6
feat(httpcache): ignore routes cfg
2 files changed,  +15, -4
+1, -0
......@@ -120,6 +120,7 @@ func NewPgsHttpCache(cfg *PgsConfig, upstream http.Handler) *httpcache.HttpCache
120120 TxtPrefix: cfg.TxtPrefix,
121121 },
122122 CacheMetrics: metrics,
123+ IgnoreRoutes: []string{"/check", "/_metrics"},
123124 }
124125 httpCache.Logger.Info("httpcache initiated", "ttl", httpCache.Ttl, "storage", "lru")
125126 return httpCache
+14, -4
......@@ -45,10 +45,11 @@ func (p *DefaultCacheMetrics) AddUpstreamRequest() {}
4545 type HttpCache struct {
4646 CacheKey
4747 CacheMetrics
48- Ttl time.Duration
49- Upstream http.Handler
50- Cache Cacher
51- Logger *slog.Logger
48+ Ttl time.Duration
49+ Upstream http.Handler
50+ Cache Cacher
51+ Logger *slog.Logger
52+ IgnoreRoutes []string
5253 }
5354
5455 func NewHttpCache(log *slog.Logger, upstream http.Handler) *HttpCache {
......@@ -71,6 +72,15 @@ func (c *HttpCache) ServeHTTP(w http.ResponseWriter, r *http.Request) {
7172 http.Error(w, "upstream http handler not found", http.StatusNotFound)
7273 return
7374 }
75+
76+ reqUri := r.URL.RequestURI()
77+ for _, uri := range c.IgnoreRoutes {
78+ if uri == reqUri {
79+ c.Upstream.ServeHTTP(w, r)
80+ return
81+ }
82+ }
83+
7484 cacheKey := c.GetCacheKey(r)
7585 log := c.Logger.With("cache_key", cacheKey)
7686