-
-
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
Add cloudflare cache #4412
Add cloudflare cache #4412
Conversation
🦋 Changeset detectedLatest commit: f877449 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
@johnwalshuk You aren't checking for the max-age(time nor even is it present) as far as i can see |
Cloudflare inspects the response headers automatically. See https://developers.cloudflare.com/workers/runtime-apis/cache/#headers |
Didn't know that, but still, relying on it isn't really advisable. |
@PH4NTOMiki why? The only things to be wary of are invalid parameters and errors. But there's a try/catch in place already so both can be ignored in this case. Personally I manually check before any calls to |
Co-authored-by: Luke Edwards <luke.edwards05@gmail.com>
@lukeed okay, if you say that, then I stand corrected. but as you said personally, checking it is nice, and it's clearer what's going on in the code. |
platform: { env, context }, | ||
getClientAddress() { | ||
return req.headers.get('cf-connecting-ip'); | ||
// @ts-ignore |
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.
Can we use ServiceWorkerGlobalScope
from @cloudflare/workers-types
so that we don't have to @ts-ignore
this?
If there's no solution then it should be turned into @ts-expect-error
along with a comment explaining why it cannot be addressed, but I would hope that it can be
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.
Hey @benmccann, I tried to add the package above but it started to throw ~30 errors in the JS files so for now I've used @ts-expect-error
with a comment as to why.
how can I disable this feature? |
I'm not sure if it's the right solution (or if we had the same problem 😅).
Edit: removed |
The cache-control header is the only relevant header here |
how can configure it for disable cache in global layer |
You can use a global // src/hooks.js
/** @type {import('@sveltejs/kit').[Handle](https://kit.svelte.dev/docs/types#sveltejs-kit-handle)} */
export async function handle({ event, resolve }) {
event.request = new Request(event.request);
event.request.headers.set('cache-control', 'no-cache');
let response = await resolve(event);
response = new Response(response.body, response);
response.headers.set('cache-control', 'no-cache');
return response;
}
|
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
pnpx changeset
and following the prompts. All changesets should bepatch
until SvelteKit 1.0Resolves #3862.
Add cache to dynamically generated pages at the edge by using the cloudflare cache api. Pages that have a cache policy (maxage) will be stored.