From 75f89fadd41dd5e394dec83f294b86553215b437 Mon Sep 17 00:00:00 2001 From: Miodec Date: Sun, 25 Sep 2022 15:41:01 +0200 Subject: [PATCH] reverted size test added else to avoid double counting --- backend/src/utils/auth.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/backend/src/utils/auth.ts b/backend/src/utils/auth.ts index 4d6bd67fa..f51df1cda 100644 --- a/backend/src/utils/auth.ts +++ b/backend/src/utils/auth.ts @@ -5,21 +5,21 @@ import LRUCache from "lru-cache"; import { recordTokenCacheAccess, setTokenCacheLength, - // setTokenCacheSize, + setTokenCacheSize, } from "./prometheus"; const tokenCache = new LRUCache({ max: 20000, - // maxSize: 20000000, // 20MB - // sizeCalculation: (token, key): number => - // JSON.stringify(token).length + key.length, //sizeInBytes + maxSize: 20000000, // 20MB + sizeCalculation: (token, key): number => + JSON.stringify(token).length + key.length, //sizeInBytes }); const TOKEN_CACHE_BUFFER = 1000 * 60 * 5; // 5 minutes export async function verifyIdToken(idToken: string): Promise { setTokenCacheLength(tokenCache.size); - // setTokenCacheSize(tokenCache.calculatedSize ?? 0); + setTokenCacheSize(tokenCache.calculatedSize ?? 0); const cached = tokenCache.get(idToken); @@ -33,8 +33,9 @@ export async function verifyIdToken(idToken: string): Promise { recordTokenCacheAccess("hit"); return cached; } + } else { + recordTokenCacheAccess("miss"); } - recordTokenCacheAccess("miss"); const decoded = await admin.auth().verifyIdToken(idToken, true); tokenCache.set(idToken, decoded);