Skip to content
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

Update api doc #1216

Merged
merged 1 commit into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/hydrogen/docs/generated/generated_docs_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -9252,7 +9252,7 @@
"tabs": [
{
"title": "JavaScript",
"code": "// In your app's `server.ts` file:\nimport * as remixBuild from '@remix-run/dev/server-build';\nimport {createWithCache_unstable, CacheLong} from '@shopify/hydrogen';\n// Use another `createRequestHandler` if deploying off oxygen\nimport {createRequestHandler} from '@shopify/remix-oxygen';\n\nexport default {\n async fetch(request, env, executionContext) {\n const cache = await caches.open('my-cms');\n const withCache = createWithCache_unstable({\n cache,\n waitUntil: executionContext.waitUntil,\n });\n\n // Create a custom utility to query a third-party API:\n const fetchMyCMS = (query) => {\n // Prefix the cache key and make it unique based on arguments.\n return withCache(['my-cms', query], CacheLong(), async () => {\n return await (\n await fetch('my-cms.com/api', {\n method: 'POST',\n body: query,\n })\n ).json();\n });\n };\n\n const handleRequest = createRequestHandler({\n build: remixBuild,\n mode: process.env.NODE_ENV,\n getLoadContext: () => ({\n /* ... */\n fetchMyCMS,\n }),\n });\n\n return handleRequest(request);\n },\n};\n",
"code": "// In your app's `server.ts` file:\nimport * as remixBuild from '@remix-run/dev/server-build';\nimport {createWithCache, CacheLong} from '@shopify/hydrogen';\n// Use another `createRequestHandler` if deploying off oxygen\nimport {createRequestHandler} from '@shopify/remix-oxygen';\n\nexport default {\n async fetch(request, env, executionContext) {\n const cache = await caches.open('my-cms');\n const withCache = createWithCache({\n cache,\n waitUntil: executionContext.waitUntil,\n });\n\n // Create a custom utility to query a third-party API:\n const fetchMyCMS = (query) => {\n // Prefix the cache key and make it unique based on arguments.\n return withCache(['my-cms', query], CacheLong(), async () => {\n return await (\n await fetch('my-cms.com/api', {\n method: 'POST',\n body: query,\n })\n ).json();\n });\n };\n\n const handleRequest = createRequestHandler({\n build: remixBuild,\n mode: process.env.NODE_ENV,\n getLoadContext: () => ({\n /* ... */\n fetchMyCMS,\n }),\n });\n\n return handleRequest(request);\n },\n};\n",
"language": "js"
},
{
Expand Down
4 changes: 2 additions & 2 deletions packages/hydrogen/src/with-cache.example.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// In your app's `server.ts` file:
import * as remixBuild from '@remix-run/dev/server-build';
import {createWithCache_unstable, CacheLong} from '@shopify/hydrogen';
import {createWithCache, CacheLong} from '@shopify/hydrogen';
// Use another `createRequestHandler` if deploying off oxygen
import {createRequestHandler} from '@shopify/remix-oxygen';

export default {
async fetch(request, env, executionContext) {
const cache = await caches.open('my-cms');
const withCache = createWithCache_unstable({
const withCache = createWithCache({
cache,
waitUntil: executionContext.waitUntil,
});
Expand Down