Skip to content

Commit

Permalink
Allow disabling memoization for all requests of a client
Browse files Browse the repository at this point in the history
  • Loading branch information
mairatma committed Oct 4, 2023
1 parent 566900b commit b37bfb8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/HttpClient/HttpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export class HttpClient {

private logger: Logger
private cacheableType: CacheType
private memoizable: boolean

private runMiddlewares: compose.ComposedMiddleware<MiddlewareContext>

Expand All @@ -49,6 +50,7 @@ export class HttpClient {
authType,
memoryCache,
diskCache,
memoizable = true,
locale,
name,
metrics,
Expand Down Expand Up @@ -79,6 +81,7 @@ export class HttpClient {
this.name = name || baseURL || 'unknown'
this.logger = logger
this.cacheableType = cacheableType
this.memoizable = memoizable

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

private getConfig = (url: string, config: RequestConfig = {}): CacheableRequestConfig => ({
cacheable: this.cacheableType,
memoizable: true,
memoizable: this.memoizable,
...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 @@ -83,6 +83,7 @@ export interface InstanceOptions {
timeout?: number
memoryCache?: CacheLayer<string, Cached>
diskCache?: CacheLayer<string, Cached>
memoizable?: boolean
baseURL?: string
retries?: number
exponentialTimeoutCoefficient?: number
Expand Down

0 comments on commit b37bfb8

Please sign in to comment.