Skip to content

Commit c3f69fd

Browse files
committed
Merge branch 'master' into metrics/requestDetailsTrace
2 parents b519801 + bf2a84e commit c3f69fd

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,18 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
77

88
## [Unreleased]
99

10+
## [6.46.0] - 2023-10-25
1011
### Added
11-
1212
- Add disk cache steps and retry count to tracing
1313

14+
### Changed
15+
- Stop updating client cache when revalidated and still expired
16+
1417
## [6.45.24] - 2023-10-05
1518
### Added
1619

1720
- Allow disabling memoization for all requests of a client
21+
1822
## [6.45.23] - 2023-10-04
1923

2024
### Fixed

src/HttpClient/middlewares/cache.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,15 @@ export const cacheMiddleware = ({ type, storage }: CacheOptions) => {
211211
? (data as Buffer).toString(responseEncoding)
212212
: data
213213

214-
const expiration = Date.now() + (maxAge - currentAge) * 1000
214+
const now = Date.now()
215+
const expiration = now + (maxAge - currentAge) * 1000
216+
217+
const alreadyExpired = expiration <= now
218+
const reusingRevalidatedCache = cached && (ctx.response === cached.response)
219+
const shouldSkipCacheUpdate = alreadyExpired && reusingRevalidatedCache
220+
if (shouldSkipCacheUpdate) {
221+
return
222+
}
215223

216224
const cacheWriteSpan = createCacheSpan(cacheType, 'write', tracer, span)
217225
try {

0 commit comments

Comments
 (0)