| 14 | |
| 15 | const SessionCache = class WeakSessionCache { |
| 16 | constructor (maxCachedSessions) { |
| 17 | this._maxCachedSessions = maxCachedSessions |
| 18 | this._sessionCache = new Map() |
| 19 | this._sessionRegistry = new FinalizationRegistry((key) => { |
| 20 | if (this._sessionCache.size < this._maxCachedSessions) { |
| 21 | return |
| 22 | } |
| 23 | |
| 24 | const ref = this._sessionCache.get(key) |
| 25 | if (ref !== undefined && ref.deref() === undefined) { |
| 26 | this._sessionCache.delete(key) |
| 27 | } |
| 28 | }) |
| 29 | } |
| 30 | |
| 31 | get (sessionKey) { |
| 32 | const ref = this._sessionCache.get(sessionKey) |