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 46c2402
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions .changeset/swift-glasses-remain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
'@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});
}
```

The utility is unstable and subject to change before stabalizing in the 2023.04 release.

0 comments on commit 46c2402

Please sign in to comment.