Skip to content

Commit

Permalink
Merge pull request #547 from vtex/feat/disableMemoFlag
Browse files Browse the repository at this point in the history
Allow disabling memoization for all requests of a client
  • Loading branch information
filafb authored Oct 5, 2023
2 parents dcda99c + 9ac2853 commit 99186f4
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ 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
## [6.45.23] - 2023-10-04

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
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
12 changes: 12 additions & 0 deletions src/HttpClient/typings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,18 @@ export interface InstanceOptions {
timeout?: number
memoryCache?: CacheLayer<string, Cached>
diskCache?: CacheLayer<string, Cached>

/**
* 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
Expand Down

0 comments on commit 99186f4

Please sign in to comment.