更新 proxy/handler.go

This commit is contained in:
XOF
2025-12-15 06:02:41 +08:00
parent e3b6c775b2
commit e9340c70f9

View File

@@ -109,12 +109,12 @@ func (h *ProxyHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}
if entry := h.cache.Get(targetURL); entry != nil {
cacheKey := h.cache.GenerateKey(targetURL)
if entry := h.cache.Get(cacheKey); entry != nil {
log.Printf("Cache HIT: %s", targetURL)
h.serveCached(w, entry)
return
}
log.Printf("Cache MISS: %s", targetURL)
proxyReq, err := http.NewRequest(r.Method, targetURL, r.Body)
@@ -163,7 +163,7 @@ func (h *ProxyHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
headers[key] = values[0]
}
}
h.cache.Set(targetURL, body, headers)
h.cache.Set(cacheKey, body, headers)
}
h.sendResponse(w, resp, body)