-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[doc] more information on depends
and invalidate
#6489
Conversation
|
@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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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! |
depends
andinvalidate
are 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 test
and lint the project withpnpm lint
andpnpm check
Changesets
pnpm changeset
and following the prompts. All changesets should bepatch
until SvelteKit 1.0