Skip to content

Commit

Permalink
Merge pull request #532 from vtex/fix/enable-disk-cache
Browse files Browse the repository at this point in the history
fix: add cacheableType for httpclient
  • Loading branch information
eduardocesb authored Jul 6, 2023
2 parents 65b1396 + 22c5a57 commit 861a294
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/HttpClient/HttpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ export class HttpClient {
public name: string

private logger: Logger
private cacheableType: CacheType

private runMiddlewares: compose.ComposedMiddleware<MiddlewareContext>

public constructor(opts: ClientOptions) {
Expand Down Expand Up @@ -72,9 +74,11 @@ export class HttpClient {
httpsAgent,
tracer,
logger,
cacheableType = CacheType.Memory,
} = opts
this.name = name || baseURL || 'unknown'
this.logger = logger
this.cacheableType = cacheableType

const limit = concurrency && concurrency > 0 && pLimit(concurrency) || undefined
const headers: Record<string, string> = {
Expand Down Expand Up @@ -205,7 +209,7 @@ export class HttpClient {
}

private getConfig = (url: string, config: RequestConfig = {}): CacheableRequestConfig => ({
cacheable: CacheType.Memory,
cacheable: this.cacheableType,
memoizable: true,
...config,
url,
Expand Down
1 change: 1 addition & 0 deletions src/HttpClient/typings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ export interface InstanceOptions {
name?: string
serverTimings?: Record<string, string>
httpsAgent?: AxiosRequestConfig['httpsAgent']
cacheableType?: CacheType
}

export interface IOResponse<T> {
Expand Down

0 comments on commit 861a294

Please sign in to comment.