Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow disabling memoization for all requests of a client #547

Merged
merged 6 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
mairatma marked this conversation as resolved.
Show resolved Hide resolved

baseURL?: string
retries?: number
exponentialTimeoutCoefficient?: number
Expand Down
Loading