-
Notifications
You must be signed in to change notification settings - Fork 204
Add support for swr with revalidateTag #1122
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
Merged
Merged
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
45f9461
feat(tagCache): add support for stale and expiry properties in Dynamo…
conico974 8c2e0a2
feat(tagCache): enhance revalidation logic with expiry and stale prop…
conico974 0640fb4
feat(tagCache): implement hasBeenStale method for tag revalidation an…
conico974 ea56122
add test for swr with revalidateTag
conico974 12f594c
linting
conico974 2c04613
feat(cache): implement stale tag handling in Cache class and update l…
conico974 09348a7
linting
conico974 ea37677
feat(patchNextServer): add rule to provide internal waitUntil functio…
conico974 cc67c92
feat(cache): refactor hasBeenStale logic and update related interface…
conico974 74c17a1
linting
conico974 4485b3f
Introduce request cache
conico974 6bee697
feat(cache): implement request caching for DynamoDB tag retrieval and…
conico974 ba75736
feat(tests): add unit tests for dynamodb tagCache functionality
conico974 ca24a37
fix unit test
conico974 dc62639
linting
conico974 7390f29
changeset
conico974 d23a850
update changeset for the breaking change
conico974 a0bffd9
review
conico974 1c230e4
refactor: rename hasBeenStale to isStale for consistency in cache han…
conico974 4419b31
refactor: replace 'expiry' with 'expire' for consistency across cache…
conico974 9392acd
refactor: replace version checks with compareSemver utility for consi…
conico974 fdaf39e
refactor: enhance type safety in request cache and improve tag cache …
conico974 b1271fb
linting
conico974 d552686
review
conico974 594a00a
rename hasBeenStale to isStale
conico974 d92673b
linting
conico974 185e81a
Merge remote-tracking branch 'origin/main' into conico/swr-tag
conico974 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,16 @@ | ||
| --- | ||
| "@opennextjs/aws": minor | ||
| --- | ||
|
|
||
| Add support for SWR (stale-while-revalidate) in `revalidateTag` | ||
|
|
||
| Introduces a new optional method `isStale` in the tag cache for both the original and the next modes. The implementation is mandatory for SWR to work. | ||
|
|
||
| It also introduces a `RequestCache` utility that can be used to cache things scoped to a request (stored in the OpenNext internal AsyncLocalStorage context) | ||
|
|
||
| ### BREAKING CHANGE | ||
|
|
||
| `writeTags` for the tag cache signature has changed to `writeTags(tags: NextModeTagCacheWriteInput[]): Promise<void>` for Next mode, and `writeTags(tags: OriginalTagCacheWriteInput[]): Promise<void>` for the original mode. | ||
| This is breaking only for custom tag cache implementations, if you are using the default one provided by OpenNext, you don't need to do anything. | ||
|
|
||
| `globalThis.isNextAfter15` is no longer available in the cache. |
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,10 @@ | ||
| import { revalidateTag } from "next/cache"; | ||
|
|
||
| export const dynamic = "force-dynamic"; | ||
|
|
||
| export async function GET() { | ||
| // Revalidate with expire:10 to mark the tag as stale immediately and set expiry to 10 seconds later | ||
| revalidateTag("revalidate-stale", { expire: 10 }); | ||
|
|
||
| return new Response("ok"); | ||
| } |
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,20 @@ | ||
| import { unstable_cache } from "next/cache"; | ||
|
|
||
| const getCachedTime = unstable_cache( | ||
| async () => new Date().toISOString(), | ||
| ["stale-revalidate-time"], | ||
| { | ||
| tags: ["revalidate-stale"], | ||
| // Long revalidate time so the cache only expires via revalidateTag | ||
| revalidate: 3600, | ||
| }, | ||
| ); | ||
|
|
||
| export default async function StaleRevalidateTag() { | ||
| const cachedTime = await getCachedTime(); | ||
| return ( | ||
| <div> | ||
| <p data-testid="cached-time">Cached time: {cachedTime}</p> | ||
| </div> | ||
| ); | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.