From b37bfb8549ff32b6df9e9d4e5de400a9b17a31f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mai=CC=81ra=20Bello?= Date: Wed, 4 Oct 2023 15:38:20 -0300 Subject: [PATCH 1/5] Allow disabling memoization for all requests of a client --- src/HttpClient/HttpClient.ts | 5 ++++- src/HttpClient/typings.ts | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/HttpClient/HttpClient.ts b/src/HttpClient/HttpClient.ts index 5fb2033d..5b3e4ab2 100644 --- a/src/HttpClient/HttpClient.ts +++ b/src/HttpClient/HttpClient.ts @@ -39,6 +39,7 @@ export class HttpClient { private logger: Logger private cacheableType: CacheType + private memoizable: boolean private runMiddlewares: compose.ComposedMiddleware @@ -49,6 +50,7 @@ export class HttpClient { authType, memoryCache, diskCache, + memoizable = true, locale, name, metrics, @@ -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 = { @@ -210,7 +213,7 @@ export class HttpClient { private getConfig = (url: string, config: RequestConfig = {}): CacheableRequestConfig => ({ cacheable: this.cacheableType, - memoizable: true, + memoizable: this.memoizable, ...config, url, }) diff --git a/src/HttpClient/typings.ts b/src/HttpClient/typings.ts index a5183c0b..2b0deb33 100644 --- a/src/HttpClient/typings.ts +++ b/src/HttpClient/typings.ts @@ -83,6 +83,7 @@ export interface InstanceOptions { timeout?: number memoryCache?: CacheLayer diskCache?: CacheLayer + memoizable?: boolean baseURL?: string retries?: number exponentialTimeoutCoefficient?: number From f620e43ba4b665a94f52eed27678939559f0d5bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mai=CC=81ra=20Bello?= Date: Wed, 4 Oct 2023 16:03:41 -0300 Subject: [PATCH 2/5] Add entry to CHANGELOG.md --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b3a45627..ce212c0d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +- Allow disabling memoization for all requests of a client + ## [6.45.22] - 2023-09-20 ### Removed From 82890412059635ae39b91aaf6a1990de87a12205 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mai=CC=81ra=20Bello?= Date: Wed, 4 Oct 2023 16:05:16 -0300 Subject: [PATCH 3/5] Fix CHANGELOG.md --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ce212c0d..10157a53 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +### Added + - Allow disabling memoization for all requests of a client ## [6.45.22] - 2023-09-20 From fb4268e122e197e02beb460c35ff7c16c2812b17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mai=CC=81ra=20Bello?= Date: Thu, 5 Oct 2023 11:35:49 -0300 Subject: [PATCH 4/5] Add documentationf for the new flag --- src/HttpClient/typings.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/HttpClient/typings.ts b/src/HttpClient/typings.ts index 2b0deb33..6d19620c 100644 --- a/src/HttpClient/typings.ts +++ b/src/HttpClient/typings.ts @@ -83,7 +83,18 @@ export interface InstanceOptions { timeout?: number memoryCache?: CacheLayer diskCache?: CacheLayer + + /** + * Enables memoization, ephemeral within each request, for all requests of this client. + * Useful for services that makes recursive requests, like graphql resolvers, which + * might fetch the same endpoint more than once. + * If that's not the case for your service, disabling it might improve the CPU and + * memory usage. + * + * Default value: true + */ memoizable?: boolean + baseURL?: string retries?: number exponentialTimeoutCoefficient?: number From 9ac2853ee04d9d09e400ce452e207d66bedfd649 Mon Sep 17 00:00:00 2001 From: Filadelfo Date: Thu, 5 Oct 2023 11:49:58 -0300 Subject: [PATCH 5/5] Bump version --- CHANGELOG.md | 1 + package.json | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 18a95934..26025a4e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +## [6.45.24] - 2023-10-05 ### Added - Allow disabling memoization for all requests of a client diff --git a/package.json b/package.json index 109f9c01..a05d8e89 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@vtex/api", - "version": "6.45.23", + "version": "6.45.24", "description": "VTEX I/O API client", "main": "lib/index.js", "typings": "lib/index.d.ts",