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 | |
| 120 | 120 | TxtPrefix: cfg.TxtPrefix, | |
| 121 | 121 | }, | |
| 122 | 122 | CacheMetrics: metrics, | |
| 123 | + | IgnoreRoutes: []string{"/check", "/_metrics"}, | |
| 123 | 124 | } | |
| 124 | 125 | httpCache.Logger.Info("httpcache initiated", "ttl", httpCache.Ttl, "storage", "lru") | |
| 125 | 126 | return httpCache |
+14,
-4
| ... | ... | @@ -45,10 +45,11 @@ func (p *DefaultCacheMetrics) AddUpstreamRequest() {} | |
| 45 | 45 | type HttpCache struct { | |
| 46 | 46 | CacheKey | |
| 47 | 47 | 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 | |
| 52 | 53 | } | |
| 53 | 54 | ||
| 54 | 55 | func NewHttpCache(log *slog.Logger, upstream http.Handler) *HttpCache { |
| ... | ... | @@ -71,6 +72,15 @@ func (c *HttpCache) ServeHTTP(w http.ResponseWriter, r *http.Request) { | |
| 71 | 72 | http.Error(w, "upstream http handler not found", http.StatusNotFound) | |
| 72 | 73 | return | |
| 73 | 74 | } | |
| 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 | + | ||
| 74 | 84 | cacheKey := c.GetCacheKey(r) | |
| 75 | 85 | log := c.Logger.With("cache_key", cacheKey) | |
| 76 | 86 |