MCPcopy
hub / github.com/nodejs/undici / set

Method set

lib/core/connect.js:36–59  ·  view source on GitHub ↗
(sessionKey, session)

Source from the content-addressed store, hash-verified

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
62function buildConnector ({ allowH2, preferH2, useH2c, maxCachedSessions, socketPath, timeout, session: customSession, ...opts }) {

Callers 1

buildConnectorFunction · 0.45

Calls 4

hasMethod · 0.65
deleteMethod · 0.65
nextMethod · 0.65
keysMethod · 0.65

Tested by

no test coverage detected