Skip to content

Commit 68d576c

Browse files
author
Arthur Bond
authored
Clarify LRUCache usage (#76)
1 parent e647b21 commit 68d576c

3 files changed

Lines changed: 18 additions & 0 deletions

File tree

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+
### Added
11+
12+
- Clarification about `LRUCache` usage
13+
1014
## [0.2.21] - 2023-02-24
1115

1216
### Fixed

node/clients/status.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,14 @@ export default class Status extends ExternalClient {
1919
metric: 'status-get-raw',
2020
})
2121
}
22+
23+
public async getStatusAndForceMaxAge(
24+
status: number
25+
): Promise<IOResponse<string>> {
26+
return this.http.get(status.toString(), {
27+
// when using an LRUCache, this will force the response to be cached
28+
forceMaxAge: 5000,
29+
metric: 'status-get-forceMaxAge',
30+
})
31+
}
2232
}

node/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ import { validate } from './middlewares/validate'
88
const TIMEOUT_MS = 800
99

1010
// Create a LRU memory cache for the Status client.
11+
// The 'max' parameter sets the size of the cache.
1112
// The @vtex/api HttpClient respects Cache-Control headers and uses the provided cache.
13+
// Note that the response from the API being called must include an 'etag' header
14+
// or a 'cache-control' header with a 'max-age' value. If neither exist, the response will not be cached.
15+
// To force responses to be cached, consider adding the `forceMaxAge` option to your client methods.
1216
const memoryCache = new LRUCache<string, any>({ max: 5000 })
1317

1418
metrics.trackCache('status', memoryCache)

0 commit comments

Comments
 (0)