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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user