| 3159 | return ref ? ref.deref() : null; |
| 3160 | } |
| 3161 | set(sessionKey, session) { |
| 3162 | if (this._maxCachedSessions === 0) { |
| 3163 | return; |
| 3164 | } |
| 3165 | if (this._sessionCache.has(sessionKey)) { |
| 3166 | this._sessionCache.delete(sessionKey); |
| 3167 | } else if (this._sessionCache.size >= this._maxCachedSessions) { |
| 3168 | for (const [key, ref] of this._sessionCache) { |
| 3169 | if (ref.deref() === void 0) { |
| 3170 | this._sessionCache.delete(key); |
| 3171 | return; |
| 3172 | } |
| 3173 | } |
| 3174 | const oldest = this._sessionCache.keys().next(); |
| 3175 | if (!oldest.done) { |
| 3176 | this._sessionCache.delete(oldest.value); |
| 3177 | } |
| 3178 | } |
| 3179 | this._sessionCache.set(sessionKey, new WeakRef(session)); |
| 3180 | this._sessionRegistry.register(session, sessionKey); |
| 3181 | } |
| 3182 | }; |
| 3183 | function buildConnector({ allowH2, preferH2, useH2c, maxCachedSessions, socketPath, timeout, session: customSession, ...opts }) { |
| 3184 | if (maxCachedSessions != null && (!Number.isInteger(maxCachedSessions) || maxCachedSessions < 0)) { |