Move sweep before cache lookup to simplify expired entry handling

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
Fredrik Adelöw
2026-05-19 14:09:58 +02:00
parent 2f0519cba3
commit 644adbd19a
@@ -58,14 +58,6 @@ export class CachedUserInfoService implements UserInfoService {
const now = Date.now();
const cached = this.#entries.get(token);
if (cached) {
if (cached.expiresAt > now) {
return cached.promise;
}
this.#entries.delete(token);
}
if (now - this.#lastSweep > SWEEP_INTERVAL_MS) {
this.#lastSweep = now;
for (const [key, entry] of this.#entries) {
@@ -75,6 +67,11 @@ export class CachedUserInfoService implements UserInfoService {
}
}
const cached = this.#entries.get(token);
if (cached && cached.expiresAt > now) {
return cached.promise;
}
const promise = this.#delegate.getUserInfo(credentials).catch(error => {
this.#entries.delete(token);
throw error;