-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
feat: remote functions cache API #15678
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
Draft
dummdidumm
wants to merge
2
commits into
main
Choose a base branch
from
remote-functions-cache
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,9 @@ | ||
| --- | ||
| '@sveltejs/kit': minor | ||
| '@sveltejs/adapter-node': patch | ||
| '@sveltejs/adapter-vercel': patch | ||
| '@sveltejs/adapter-netlify': patch | ||
| '@sveltejs/adapter-cloudflare': patch | ||
| --- | ||
|
|
||
| feat: add `event.cache` for responses, remote query cache/invalidation, and adapter integrations |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -328,12 +328,61 @@ export interface Emulator { | |
| platform?(details: { config: any; prerender: PrerenderOption }): MaybePromise<App.Platform>; | ||
| } | ||
|
|
||
| /** | ||
| * Options for [`query.cache`](https://svelte.dev/docs/kit/remote-functions#Caching) | ||
| */ | ||
| export interface CacheOptions { | ||
| ttl: string | number; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be a type like `${number}d` | `${number}h` | `${number}m` | `${number}s` | `${number}ms`
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ms/day don't really make sense imo but otherwise yes; on my list of todos once we agree on the API 👍 |
||
| stale?: string | number; | ||
| /** @default 'private' */ | ||
| scope?: 'public' | 'private'; | ||
| tags?: string[]; | ||
| /** @default false */ | ||
| refresh?: boolean; | ||
| } | ||
|
|
||
| /** | ||
| * Normalized cache directive passed to custom `kit.cache` handlers. | ||
| */ | ||
| export interface KitCacheDirective { | ||
| scope: 'public' | 'private'; | ||
| maxAgeSeconds: number; | ||
| staleSeconds?: number; | ||
| tags: string[]; | ||
| refresh: boolean; | ||
| } | ||
|
|
||
| /** | ||
| * Custom cache integration (e.g. platform purge hooks). Export `create` or `default` from `kit.cache.path`. | ||
| */ | ||
| export interface KitCacheHandler { | ||
| setHeaders?( | ||
| headers: Headers, | ||
| directive: KitCacheDirective, | ||
| ctx: { remote_id?: string | null } | ||
| ): MaybePromise<void>; | ||
| invalidate?(tags: string[]): MaybePromise<void>; | ||
| } | ||
|
|
||
| export interface RequestCache { | ||
| (arg: CacheOptions | string): void; | ||
| invalidate(tags: string[]): void; | ||
| } | ||
|
|
||
| export interface KitConfig { | ||
| /** | ||
| * Your [adapter](https://svelte.dev/docs/kit/adapters) is run when executing `vite build`. It determines how the output is converted for different platforms. | ||
| * @default undefined | ||
| */ | ||
| adapter?: Adapter; | ||
| /** | ||
| * Optional module that implements [`KitCacheHandler`](https://svelte.dev/docs/kit/@sveltejs-kit#KitCacheHandler) via a `create` or default export function. | ||
| */ | ||
| cache?: { | ||
| /** Absolute or project-relative path resolved from your app root */ | ||
| path?: string; | ||
| options?: Record<string, unknown>; | ||
| }; | ||
| /** | ||
| * An object containing zero or more aliases used to replace values in `import` statements. These aliases are automatically passed to Vite and TypeScript. | ||
| * | ||
|
|
@@ -2178,6 +2227,10 @@ export type RemoteQuery<T> = RemoteResource<T> & { | |
| * This prevents SvelteKit needing to refresh all queries on the page in a second server round-trip. | ||
| */ | ||
| refresh(): Promise<void>; | ||
| /** | ||
| * Queue cache invalidation for this query (public or private, depending on how it was cached). | ||
| */ | ||
| invalidate(): void; | ||
| /** | ||
| * Temporarily override a query's value during a [single-flight mutation](https://svelte.dev/docs/kit/remote-functions#Single-flight-mutations) to provide optimistic updates. | ||
| * | ||
|
|
@@ -2210,7 +2263,7 @@ export type RemotePrerenderFunction<Input, Output> = ( | |
| ) => RemoteResource<Output>; | ||
|
|
||
| /** | ||
| * The return value of a remote `query` function. See [Remote functions](https://svelte.dev/docs/kit/remote-functions#query) for full documentation. | ||
| * The return value of a remote `query` function (client stub or shared typing). See [Remote functions](https://svelte.dev/docs/kit/remote-functions#query) for full documentation. | ||
| */ | ||
| export type RemoteQueryFunction<Input, Output> = ( | ||
| arg: undefined extends Input ? Input | void : Input | ||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I don't think the URL is the right cache key here... it should probably be the remote function key instead. Also, tags should be additive, not replace the default key.