internal/frontend: add vuln pages to redis cache

Change-Id: I1d4126a7f040c8926ab573a915d7fc1eac61619d
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/435376
Reviewed-by: Jonathan Amsterdam <jba@google.com>
Run-TryBot: Jamal Carvalho <jamal@golang.org>
TryBot-Result: kokoro <noreply+kokoro@google.com>
diff --git a/internal/frontend/server.go b/internal/frontend/server.go
index 8d358bf..901d492 100644
--- a/internal/frontend/server.go
+++ b/internal/frontend/server.go
@@ -129,10 +129,12 @@
 		detailHandler http.Handler = s.errorHandler(s.serveDetails)
 		fetchHandler  http.Handler = s.errorHandler(s.serveFetch)
 		searchHandler http.Handler = s.errorHandler(s.serveSearch)
+		vulnHandler   http.Handler = s.errorHandler(s.serveVuln)
 	)
 	if redisClient != nil {
 		detailHandler = middleware.Cache("details", redisClient, detailsTTL, authValues)(detailHandler)
 		searchHandler = middleware.Cache("search", redisClient, searchTTL, authValues)(searchHandler)
+		vulnHandler = middleware.Cache("vuln", redisClient, vulnTTL, authValues)(vulnHandler)
 	}
 	// Each AppEngine instance is created in response to a start request, which
 	// is an empty HTTP GET request to /_ah/start when scaling is set to manual
@@ -171,7 +173,7 @@
 	}))
 	handle("/golang.org/x", s.staticPageHandler("subrepo", "Sub-repositories"))
 	handle("/files/", http.StripPrefix("/files", s.fileMux))
-	handle("/vuln/", http.StripPrefix("/vuln", s.errorHandler(s.serveVuln)))
+	handle("/vuln/", http.StripPrefix("/vuln", vulnHandler))
 	handle("/", detailHandler)
 	if s.serveStats {
 		handle("/detail-stats/",
@@ -355,6 +357,11 @@
 	return symbolSearchTTL
 }
 
+// vulnTTL assigns the cache TTL for vuln requests.
+func vulnTTL(r *http.Request) time.Duration {
+	return defaultTTL
+}
+
 // TagRoute categorizes incoming requests to the frontend for use in
 // monitoring.
 func TagRoute(route string, r *http.Request) string {