Skip to content
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,10 +7,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Changed
- Stop updating client cache when revalidated and still expired

## [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
11 changes: 10 additions & 1 deletion src/HttpClient/middlewares/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,16 @@ export const cacheMiddleware = ({ type, storage }: CacheOptions) => {
? (data as Buffer).toString(responseEncoding)
: data

const expiration = Date.now() + (maxAge - currentAge) * 1000
const now = Date.now()
const expiration = now + (maxAge - currentAge) * 1000

const alreadyExpired = expiration <= now
const reusingRevalidatedCache = cached && (ctx.response === cached.response)
const shouldSkipCacheUpdate = alreadyExpired && reusingRevalidatedCache
if (shouldSkipCacheUpdate) {
return
}

await storage.set(setKey, {
etag,
expiration,
Expand Down