(options: ImpitOptions)
| 36 | private clientCache: LruCache<{ client: Impit; cookieJar: ToughCookieJar }> = new LruCache({ maxLength: 10 }); |
| 37 | |
| 38 | private getClient(options: ImpitOptions) { |
| 39 | const { cookieJar, ...rest } = options; |
| 40 | |
| 41 | const cacheKey = JSON.stringify(rest); |
| 42 | const existingClient = this.clientCache.get(cacheKey); |
| 43 | |
| 44 | if (existingClient && (!cookieJar || existingClient.cookieJar === cookieJar)) { |
| 45 | return existingClient.client; |
| 46 | } |
| 47 | |
| 48 | const client = new Impit(options); |
| 49 | this.clientCache.add(cacheKey, { client, cookieJar: cookieJar as ToughCookieJar }); |
| 50 | |
| 51 | return client; |
| 52 | } |
| 53 | |
| 54 | constructor(options?: Omit<ImpitOptions, 'proxyUrl'> & { maxRedirects?: number }) { |
| 55 | this.impitOptions = options ?? {}; |
no test coverage detected