(sessionKey, session)
| 34 | } |
| 35 | |
| 36 | set (sessionKey, session) { |
| 37 | if (this._maxCachedSessions === 0) { |
| 38 | return |
| 39 | } |
| 40 | |
| 41 | if (this._sessionCache.has(sessionKey)) { |
| 42 | this._sessionCache.delete(sessionKey) |
| 43 | } else if (this._sessionCache.size >= this._maxCachedSessions) { |
| 44 | for (const [key, ref] of this._sessionCache) { |
| 45 | if (ref.deref() === undefined) { |
| 46 | this._sessionCache.delete(key) |
| 47 | return |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | const oldest = this._sessionCache.keys().next() |
| 52 | if (!oldest.done) { |
| 53 | this._sessionCache.delete(oldest.value) |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | this._sessionCache.set(sessionKey, new WeakRef(session)) |
| 58 | this._sessionRegistry.register(session, sessionKey) |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | function buildConnector ({ allowH2, preferH2, useH2c, maxCachedSessions, socketPath, timeout, session: customSession, ...opts }) { |
no test coverage detected