Skip to content

Commit

Permalink
feat: reduce the frequency of cache revalidation
Browse files Browse the repository at this point in the history
  • Loading branch information
aui committed Jun 5, 2024
1 parent 8d77422 commit 0847567
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 42 deletions.
5 changes: 5 additions & 0 deletions .changeset/little-parrots-roll.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@web-widget/shared-cache": patch
---

Reduce the frequency of cache revalidation.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"lru-cache": "^10.2.0"
},
"dependencies": {
"@web-widget/http-cache-semantics": "^1.0.0",
"@web-widget/http-cache-semantics": "^1.1.0",
"@web-widget/helpers": "^1.10.37"
},
"packageManager": "pnpm@8.4.0",
Expand Down
78 changes: 39 additions & 39 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 9 additions & 2 deletions src/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,12 @@ export class SharedCache implements Cache {
headers,
});

if (!forceCache && !policy.satisfiesWithoutRevalidation(r)) {
if (
!forceCache &&
!policy.satisfiesWithoutRevalidation(r, {
ignoreSearch: true,
})
) {
if (policy.stale() && policy.useStaleWhileRevalidate()) {
// Well actually, in this case it's fine to return the stale response.
// But we'll update the cache in the background.
Expand Down Expand Up @@ -334,7 +339,9 @@ export class SharedCache implements Cache {
fetch: typeof globalThis.fetch
): Promise<Response> {
const revalidationRequest = new Request(request, {
headers: resolveCacheItem.policy.revalidationHeaders(request),
headers: resolveCacheItem.policy.revalidationHeaders(request, {
ignoreSearch: true,
}),
});
let revalidationResponse: Response;

Expand Down

0 comments on commit 0847567

Please sign in to comment.