Skip to content

Commit

Permalink
Skip cache logic when mode is no-store (#964)
Browse files Browse the repository at this point in the history
* Skip cache logic when cache mode is no-store

* Changesets
  • Loading branch information
frandiox authored Jun 1, 2023
1 parent dbc7452 commit 8ccf6db
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/modern-rats-dance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/hydrogen': patch
---

Skip reading and writing cache in sub-requests when the strategy is CacheNone.
6 changes: 4 additions & 2 deletions packages/hydrogen/src/cache/fetch.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {hashKey} from '../utils/hash.js';
import {CacheShort, CachingStrategy} from './strategies';
import {CacheShort, CachingStrategy, NO_STORE} from './strategies';
import {getItemFromCache, setItemInCache, isStale} from './sub-request';

/**
Expand Down Expand Up @@ -59,7 +59,9 @@ export async function runWithCache<T = unknown>(
waitUntil,
}: WithCacheOptions<T>,
): Promise<T> {
if (!cacheInstance || !strategy) return actionFn();
if (!cacheInstance || !strategy || strategy.mode === NO_STORE) {
return actionFn();
}

const key = hashKey([
// '__HYDROGEN_CACHE_ID__', // TODO purgeQueryCacheOnBuild
Expand Down

0 comments on commit 8ccf6db

Please # to comment.