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
Increase default cache SWR #1336
Conversation
One question I had was whether or not we should make |
Why not introduce |
Hmm … not a bad idea, I'll think about updating this so we keep That said, with this PR I really wanted to change as little as possible so there shouldn't be any disruption to current behaviour for most folks. If we increase For now I think we'll keep this as is. Certainly, I'd advocate in calls to third parties to have a higher |
@@ -0,0 +1,5 @@ | |||
--- | |||
'@shopify/hydrogen': patch |
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.
Shouldn't this be at least a minor release given that we are changing an important default behavior?
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 think this is the weird thing about changesets & calver … right @blittle? "Minor" would mean it gets bumped to 2023.08
This is definitely a DevOps oddity we need to resolve.
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.
Using calver, following storefront api release, is a decision we agree on - So everything is a patch. If it is a breaking change, we should release as in opted-in feature or unstable feature until the next calendar release.
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.
This change will make Hydrogen fast but stale. So that means that devs will need to evaluate what's the risk tolerance for a page being stale (for that 1 second) and adjust accordingly.
WHY are these changes introduced?
After some inspiration from https://www.youtube.com/watch?v=bfLFHp7Sbkg&t=1035s, and talking to a number of developers who weren't customizing their caching strategy but certainly were not getting more than 1 request per 10 seconds per page, I'd like to propose we extend SWR time by default for all requests to be 1 day.
We would still keep
max-age
to be 1 second, so the server can go and start to revalidate things right away, but the only downside to this approach from what I see is that flash sellers may have small gaps where inventory availability status is inaccurate — but I believe they should opt to useCacheShort
, where I've now changed our default to use a new strategy:CacheDefault
.🤖 Generated by Copilot at 516d829
This pull request changes the default caching strategy for the Hydrogen framework to
CacheDefault
, which improves the performance and flexibility of caching public resources. It also adds a changeset file to document the patch update for the@shopify/hydrogen
package.WHAT is this pull request doing?
🤖 Generated by Copilot at 516d829
CacheDefault
function that returns the cache options for the default strategy and accepts an optional override object (link, link)CacheShort
function with theCacheDefault
function in thegetCacheControlSetting
,getCacheOption
, andfetchStorefrontApi
functions that determine the cache options for the Hydrogen API, the sub-requests, and the GraphQL requests respectively (link, link, link)CacheDefault
function from the./strategies
module in the./api
,./sub-request
, and./storefront
modules that use it (link, link, link)HOW to test your changes?
Post-merge steps
Merge and public documentation update to indicate change to default caching: https://shopify.dev/docs/custom-storefronts/hydrogen/data-fetching/cache#cache-data-from-third-party-apis, PR here: #1336
Checklist