-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[fix] respect fetch cache option (#8024)
* [fix] respect fetch cache option fixes #7971 * fix cache key computation
- Loading branch information
1 parent
20ed756
commit ef8915f
Showing
7 changed files
with
78 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@sveltejs/kit': patch | ||
--- | ||
|
||
[fix] respect fetch cache option |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 10 additions & 1 deletion
11
packages/kit/test/apps/basics/src/routes/load/cache-control/+page.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,14 @@ | ||
let force = false; | ||
|
||
export function _force_next_fetch() { | ||
force = true; | ||
} | ||
|
||
/** @type {import('./$types').PageLoad} */ | ||
export async function load({ fetch }) { | ||
const resp = await fetch('/load/cache-control/count'); | ||
const resp = await fetch('/load/cache-control/count', { cache: force ? 'no-cache' : 'default' }); | ||
if (force) { | ||
force = false; | ||
} | ||
return resp.json(); | ||
} |
14 changes: 12 additions & 2 deletions
14
packages/kit/test/apps/basics/src/routes/load/cache-control/+page.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,24 @@ | ||
<script> | ||
import { invalidate } from '$app/navigation'; | ||
import { _force_next_fetch } from './+page'; | ||
/** @type {import('./$types').PageData} */ | ||
export let data; | ||
async function fetch_again() { | ||
/** @param {'default' | 'force' | 'bust'} type */ | ||
async function fetch_again(type) { | ||
await fetch('/load/cache-control/increment'); | ||
if (type === 'force') { | ||
_force_next_fetch(); | ||
} else if (type === 'bust') { | ||
await fetch('/load/cache-control/count', {method: 'POST'}); | ||
} | ||
invalidate('/load/cache-control/count'); | ||
} | ||
</script> | ||
|
||
<p>Count is {data.count}</p> | ||
<button on:click={fetch_again}>Fetch again</button> | ||
<button class="default" on:click={() => fetch_again('default')}>Fetch again</button> | ||
<button class="force" on:click={() => fetch_again('force')}>Fetch again (force reload)</button> | ||
<button class="bust" on:click={() => fetch_again('bust')}>Fetch again (prior POST request)</button> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters