From 36085e4854a28930a182b81b8ba5e476ed16e76f Mon Sep 17 00:00:00 2001 From: Tim Donohue Date: Fri, 20 Jan 2023 16:50:42 -0600 Subject: [PATCH] Avoid caching a page twice in a row --- server.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/server.ts b/server.ts index 8f9617834d..04a0e36670 100644 --- a/server.ts +++ b/server.ts @@ -399,7 +399,12 @@ function saveToCache(req, data: any) { // NOTE: It's not safe to save page data to the cache when a user is authenticated. In that situation, // the page may include sensitive or user-specific materials. As the cache is shared across all users, it can only contain public info. if (cacheEnabled() && !isUserAuthenticated(req)) { - cache.set(getCacheKey(req), data); + const key = getCacheKey(req); + // Make sure this key is not already in our cache. If "has()" returns true, + // then it's in the cache already and *not* expired. + if (!cache.has(key)) { + cache.set(key, data); + } } }