Skip to content

Commit 99186f4

Browse files
authored
Merge pull request #547 from vtex/feat/disableMemoFlag
Allow disabling memoization for all requests of a client
2 parents dcda99c + 9ac2853 commit 99186f4

File tree

4 files changed

+21
-2
lines changed

4 files changed

+21
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
77

88
## [Unreleased]
99

10+
## [6.45.24] - 2023-10-05
11+
### Added
12+
13+
- Allow disabling memoization for all requests of a client
1014
## [6.45.23] - 2023-10-04
1115

1216
### Fixed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@vtex/api",
3-
"version": "6.45.23",
3+
"version": "6.45.24",
44
"description": "VTEX I/O API client",
55
"main": "lib/index.js",
66
"typings": "lib/index.d.ts",

src/HttpClient/HttpClient.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export class HttpClient {
3939

4040
private logger: Logger
4141
private cacheableType: CacheType
42+
private memoizable: boolean
4243

4344
private runMiddlewares: compose.ComposedMiddleware<MiddlewareContext>
4445

@@ -49,6 +50,7 @@ export class HttpClient {
4950
authType,
5051
memoryCache,
5152
diskCache,
53+
memoizable = true,
5254
locale,
5355
name,
5456
metrics,
@@ -79,6 +81,7 @@ export class HttpClient {
7981
this.name = name || baseURL || 'unknown'
8082
this.logger = logger
8183
this.cacheableType = cacheableType
84+
this.memoizable = memoizable
8285

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

211214
private getConfig = (url: string, config: RequestConfig = {}): CacheableRequestConfig => ({
212215
cacheable: this.cacheableType,
213-
memoizable: true,
216+
memoizable: this.memoizable,
214217
...config,
215218
url,
216219
})

src/HttpClient/typings.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,18 @@ export interface InstanceOptions {
8383
timeout?: number
8484
memoryCache?: CacheLayer<string, Cached>
8585
diskCache?: CacheLayer<string, Cached>
86+
87+
/**
88+
* Enables memoization, ephemeral within each request, for all requests of this client.
89+
* Useful for services that makes recursive requests, like graphql resolvers, which
90+
* might fetch the same endpoint more than once.
91+
* If that's not the case for your service, disabling it might improve the CPU and
92+
* memory usage.
93+
*
94+
* Default value: true
95+
*/
96+
memoizable?: boolean
97+
8698
baseURL?: string
8799
retries?: number
88100
exponentialTimeoutCoefficient?: number

0 commit comments

Comments
 (0)