Cache a resolution for `ttlMs`. Evicts the oldest entry past the cap.
(bearer: string, value: ResolvedPrincipal)
| 72 | |
| 73 | /** Cache a resolution for `ttlMs`. Evicts the oldest entry past the cap. */ |
| 74 | set(bearer: string, value: ResolvedPrincipal): void { |
| 75 | const key = fingerprintBearer(bearer); |
| 76 | if (!this.map.has(key) && this.map.size >= this.opts.maxEntries) { |
| 77 | // Map preserves insertion order, so the first key is the oldest. |
| 78 | const oldest = this.map.keys().next().value; |
| 79 | if (oldest !== undefined) this.map.delete(oldest); |
| 80 | } |
| 81 | this.map.set(key, { value, expiresAt: this.opts.now() + this.opts.ttlMs }); |
| 82 | } |
| 83 | |
| 84 | size(): number { |
| 85 | return this.map.size; |