Skip to content

Commit

Permalink
Add changeset
Browse files Browse the repository at this point in the history
  • Loading branch information
blittle committed Mar 16, 2023
1 parent 53fa0fc commit 3bc1005
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions .changeset/swift-glasses-remain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
'@shopify/hydrogen': patch
---

Add an experimental `withCache_unstable` utility similar to `useQuery` from Hydrogen v1. To setup the utility, update your `server.ts`:

```diff
- const {storefront} = createStorefrontClient({
+ const {storefront, withCache_unstable} = createStorefrontClient({
...
});

const handleRequest = createRequestHandler({
build: remixBuild,
mode: process.env.NODE_ENV,
getLoadContext: () => ({
session,
waitUntil,
storefront,
env,
+ withCache_unstable,
}),
});
```

Then use the utility within your loaders:

```ts
export async function loader({context: {storefront, withCache}}: LoaderArgs) {
const data = await withCache(
'test-with-cache',
async () => {
const result = await fetch('https://www.some.com/api');
if (result.ok) {
return result.json();
} else {
throw new Error('Error: ' + result.status);
}
},
{
strategy: storefront.CacheLong(),
},
);

return json({data});
}
```

0 comments on commit 3bc1005

Please sign in to comment.