Skip to content

Commit 3d1e6b5

Browse files
iclantonclaude
andcommitted
Reuse a single WebClient instance in HttpBuildCacheProvider
A new WebClient was being constructed on every call to _makeHttpCoreRequestAsync. Since the provider never configures any WebClient instance state, a single class member suffices. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent d729a97 commit 3d1e6b5

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

rush-plugins/rush-http-build-cache-plugin/src/HttpBuildCacheProvider.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ export class HttpBuildCacheProvider implements ICloudBuildCacheProvider {
7373
private readonly _cacheKeyPrefix: string;
7474
private readonly _tokenHandler: IHttpBuildCacheTokenHandler | undefined;
7575
private readonly _minHttpRetryDelayMs: number;
76+
private readonly _webClient: WebClient = new WebClient();
7677
private __credentialCacheId: string | undefined;
7778

7879
public get isCacheWriteAllowed(): boolean {
@@ -373,7 +374,6 @@ export class HttpBuildCacheProvider implements ICloudBuildCacheProvider {
373374

374375
terminal.writeDebugLine(`[http-build-cache] request: ${method} ${url} ${bodyLength} bytes`);
375376

376-
const webClient: WebClient = new WebClient();
377377
const fetchOptions: IGetFetchOptions | IFetchOptionsWithBody = {
378378
verb: method,
379379
headers: headers,
@@ -383,8 +383,8 @@ export class HttpBuildCacheProvider implements ICloudBuildCacheProvider {
383383
};
384384

385385
const response: IWebClientResponse | IWebClientStreamResponse = stream
386-
? await webClient.fetchStreamAsync(url, fetchOptions)
387-
: await webClient.fetchAsync(url, fetchOptions);
386+
? await this._webClient.fetchStreamAsync(url, fetchOptions)
387+
: await this._webClient.fetchAsync(url, fetchOptions);
388388

389389
if (!response.ok) {
390390
// Drain the response body on stream responses so the connection can be reused

0 commit comments

Comments
 (0)