Skip to content

Set "cache-tag" on the regional cache entries #551

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 11 commits into from
Apr 9, 2025

Conversation

SamyPesse
Copy link
Contributor

This PR aims at improving the use of the regional cache by making sure that entries on it can be purged by cache-tag on Cloudflare.

In our application (https://github.com/GitbookIO/gitbook), we purge the cache both using revalidateTag but also using the Cloudflare API (https://developers.cloudflare.com/cache/how-to/purge-cache/purge-by-tags/).

I think this header has no negative impact on any other OpenNext users while unblocking us but also potentially unblocking someone who is using the long-lived cache and needs to quickly purge it (they could do it from the CF dashboard).

Copy link

changeset-bot bot commented Apr 8, 2025

🦋 Changeset detected

Latest commit: 54b0ed8

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@opennextjs/cloudflare Patch

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

Copy link

pkg-pr-new bot commented Apr 8, 2025

Open in StackBlitz

pnpm add https://pkg.pr.new/@opennextjs/cloudflare@551

commit: 54b0ed8

Copy link
Collaborator

@conico974 conico974 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, we'd want the purge to be automatic.
This means we'd have another override for the tag cache that would work in the same way as this one (by wrapping the tag cache used) and that would call cloudflare api to purge cache entry automatically on writeTags.
We'd also want to provide this https://opennext.js.org/aws/config/overrides/automatic_cdn_invalidation so that it would work for res.revalidate from page router as well.

@SamyPesse
Copy link
Contributor Author

Ideally, we'd want the purge to be automatic.
This means we'd have another override for the tag cache that would work in the same way as this one (by wrapping the tag cache used) and that would call cloudflare api to purge cache entry automatically on writeTags.
We'd also want to provide this https://opennext.js.org/aws/config/overrides/automatic_cdn_invalidation so that it would work for res.revalidate from page router as well.

It makes sense, I guess it can be done in another PR?

@conico974 I've made the other suggested changes, let me know if they match what you had in mind.

Copy link
Collaborator

@conico974 conico974 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just made 2 small comments but other than that, it looks good

It makes sense, I guess it can be done in another PR?

Yeah we can do it in another PR later.

Copy link
Collaborator

@conico974 conico974 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM Thanks

@vicb
Copy link
Contributor

vicb commented Apr 8, 2025

Thanks @SamyPesse for the PR, could you please prepare a PR for the docs at https://github.com/opennextjs/docs

@SamyPesse or @conico974 could you please create a feature request for the follow up.

Thanks!

Copy link
Contributor

@vicb vicb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's merge once the comments are resolved.

@SamyPesse
Copy link
Contributor Author

SamyPesse commented Apr 8, 2025

Thanks @vicb and @conico974, I'll merge it and look at making a PR on the docs (It'd be great to have it hosted on GitBook :D )

EDIT: I can't merge, so one of you will have to do it if changes are good for you

@SamyPesse
Copy link
Contributor Author

Actually, for the documentation, it could be better to wait for #555 before writing it as by itself this PR doesn't make it a standalone solution for most people using Opennext.

@vicb vicb force-pushed the regional-cache-tags branch from 0dde4b2 to feba75e Compare April 8, 2025 20:31
@vicb
Copy link
Contributor

vicb commented Apr 8, 2025

I added one last commit + rebase, let me know if this looks good

@SamyPesse
Copy link
Contributor Author

Perfect! thanks @vicb

@vicb vicb merged commit 8841641 into opennextjs:main Apr 9, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants