[doc] more information on depends and invalidate#6489
[doc] more information on depends and invalidate#6489icalvin102 wants to merge 3 commits intosveltejs:masterfrom
depends and invalidate#6489Conversation
|
|
@icalvin102 I have a general question about E.g. such code /** @type {import('./$types').PageLoad} */
export async function load({ fetch }) {
const url = `https://cms.example.com/articles.json`;
const url2 = `https://cms.example.com/articles2.json`;
const response = await fetch(url);
const response2 = await fetch(url2);
return {
articles: await response.json(),
articles2: await response2.json()
};And then invalidate((url) => url===`https://cms.example.com/articles.json`)`Question: does it execute the entire load after invalidate? Because it is clearly stated in It seems to me that this would make sense. Oh, and it's hard for custom depends to handle cache. |
Rich-Harris
left a comment
There was a problem hiding this comment.
thank you! couple of small comments, plus some notes about improvements to the invalidate API that i think would be worth sneaking in ahead of this
Co-authored-by: Rich Harris <hello@rich-harris.dev>
|
@lukaszpolowczyk Automatic caching of individual resources in However giving the user a way to determine which resource should be fetched again would theoretically be possible if export async function load({ fetch, isInvalidating }) {
const url = `https://cms.example.com/articles.json`;
const url2 = `https://cms.example.com/articles2.json`;
let response, response2;
if(isInvalidating(url)) {
response = await fetch(url);
cache.set(url, response);
} else {
response = cache.get(url);
}
if(isInvalidating(url2)) {
response2 = await fetch(url);
cache.set(url2, response2);
} else {
response2 = cache.get(url2);
}
return {
articles: await response.json(),
articles2: await response2.json()
};
}But this feature does currently not exist. Might be worth a feature request. |
@icalvin102 I added - #6495 |
|
incorporated this branch into #6493, so I'll close this — thanks! |
dependsandinvalidateare not documented enough.Related issues (most recently #6354) and a lot of questions on the Svelte discord server show that there is some confusion about their usage.
Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm testand lint the project withpnpm lintandpnpm checkChangesets
pnpm changesetand following the prompts. All changesets should bepatchuntil SvelteKit 1.0