Skip to content
Draft
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
5 changes: 4 additions & 1 deletion packages/hydrogen/src/storefront.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ type HydrogenClientProps<TI18n> = {
i18n?: TI18n;
/** Whether it should print GraphQL errors automatically. Defaults to true */
logErrors?: boolean | ((error?: Error) => boolean);
/** Allows for the cache to be disabled globally. Defaults to false */
disableCache?: boolean;
};

export type CreateStorefrontClientOptions<TI18n extends I18nBase> =
Expand Down Expand Up @@ -218,6 +220,7 @@ export function createStorefrontClient<TI18n extends I18nBase>(
i18n,
storefrontId,
logErrors = true,
disableCache = false,
...clientOptions
} = options;
const H2_PREFIX_WARN = '[h2:warn:createStorefrontClient] ';
Expand Down Expand Up @@ -324,7 +327,7 @@ export function createStorefrontClient<TI18n extends I18nBase>(

const [body, response] = await fetchWithServerCache(url, requestInit, {
cacheInstance: mutation ? undefined : cache,
cache: cacheOptions || CacheDefault(),
cache: disableCache ? CacheNone() : cacheOptions || CacheDefault(),
cacheKey,
shouldCacheResponse: checkGraphQLErrors,
waitUntil,
Expand Down
7 changes: 7 additions & 0 deletions templates/skeleton/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ export default {
AppSession.init(request, [env.SESSION_SECRET]),
]);

/**
* Example implemention of cache supression.
*/
const { searchParams } = new URL(request.url);
const disableCache = searchParams.get('disable-cache') === 'true';

/**
* Create Hydrogen's Storefront client.
*/
Expand All @@ -52,6 +58,7 @@ export default {
storeDomain: env.PUBLIC_STORE_DOMAIN,
storefrontId: env.PUBLIC_STOREFRONT_ID,
storefrontHeaders: getStorefrontHeaders(request),
disableCache,
});

/**
Expand Down