diff --git a/packages/hydrogen/src/cache/create-with-cache.example.ts b/packages/hydrogen/src/cache/create-with-cache.example.ts index 1c53cf18f..4c059b1e7 100644 --- a/packages/hydrogen/src/cache/create-with-cache.example.ts +++ b/packages/hydrogen/src/cache/create-with-cache.example.ts @@ -34,7 +34,7 @@ export default { { // Optionally, specify a cache strategy. // Default is CacheShort(). - cache: CacheLong(), + cacheStrategy: CacheLong(), // Cache if there are no GraphQL errors: shouldCacheResponse: (body) => !body?.errors, // Optionally, add extra information to show @@ -55,7 +55,7 @@ export default { return withCache.run( { cacheKey: ['my-cms-composite', options.id, options.handle], - strategy: CacheLong(), + cacheStrategy: CacheLong(), shouldCacheResult: () => true, }, async (params) => { diff --git a/packages/hydrogen/src/cache/create-with-cache.test.ts b/packages/hydrogen/src/cache/create-with-cache.test.ts index 33fd53fe9..25807f514 100644 --- a/packages/hydrogen/src/cache/create-with-cache.test.ts +++ b/packages/hydrogen/src/cache/create-with-cache.test.ts @@ -39,7 +39,7 @@ describe('createWithCache', () => { withCache.run( { cacheKey: KEY, - strategy: CacheNone(), + cacheStrategy: CacheNone(), shouldCacheResult: () => true, }, actionFn, @@ -54,7 +54,7 @@ describe('createWithCache', () => { withCache.run( { cacheKey: KEY, - strategy: CacheNone(), + cacheStrategy: CacheNone(), shouldCacheResult: () => true, }, actionFn, @@ -78,7 +78,7 @@ describe('createWithCache', () => { withCache.run( { cacheKey: KEY, - strategy: CacheShort(), + cacheStrategy: CacheShort(), shouldCacheResult: () => true, }, actionFn, @@ -96,7 +96,7 @@ describe('createWithCache', () => { withCache.run( { cacheKey: KEY, - strategy, + cacheStrategy: strategy, shouldCacheResult: (v) => v !== VALUE, }, actionFn, @@ -111,7 +111,7 @@ describe('createWithCache', () => { withCache.run( { cacheKey: KEY, - strategy, + cacheStrategy: strategy, shouldCacheResult: (v) => v !== VALUE, }, actionFn, @@ -130,7 +130,7 @@ describe('createWithCache', () => { withCache.run( { cacheKey: KEY, - strategy, + cacheStrategy: strategy, shouldCacheResult: () => true, }, actionFn, @@ -150,7 +150,7 @@ describe('createWithCache', () => { withCache.run( { cacheKey: KEY, - strategy, + cacheStrategy: strategy, shouldCacheResult: () => true, }, actionFn, @@ -171,7 +171,7 @@ describe('createWithCache', () => { withCache.run( { cacheKey: KEY, - strategy, + cacheStrategy: strategy, shouldCacheResult: () => true, }, actionFn, @@ -191,7 +191,7 @@ describe('createWithCache', () => { withCache.run( { cacheKey: KEY, - strategy, + cacheStrategy: strategy, shouldCacheResult: () => true, }, actionFn, @@ -217,7 +217,7 @@ describe('createWithCache', () => { withCache.run( { cacheKey: KEY, - strategy, + cacheStrategy: strategy, shouldCacheResult: () => true, }, actionFn, diff --git a/packages/hydrogen/src/cache/create-with-cache.ts b/packages/hydrogen/src/cache/create-with-cache.ts index bb9d50ec2..257e8d8d8 100644 --- a/packages/hydrogen/src/cache/create-with-cache.ts +++ b/packages/hydrogen/src/cache/create-with-cache.ts @@ -25,7 +25,7 @@ type WithCacheRunOptions = { * Use the `CachingStrategy` to define a custom caching mechanism for your data. * Or use one of the pre-defined caching strategies: [`CacheNone`](/docs/api/hydrogen/utilities/cachenone), [`CacheShort`](/docs/api/hydrogen/utilities/cacheshort), [`CacheLong`](/docs/api/hydrogen/utilities/cachelong). */ - strategy: CachingStrategy; + cacheStrategy: CachingStrategy; /** Useful to avoid accidentally caching bad results */ shouldCacheResult: (value: T) => boolean; }; @@ -36,7 +36,7 @@ type WithCacheFetchOptions = { * Use the `CachingStrategy` to define a custom caching mechanism for your data. * Or use one of the pre-defined caching strategies: [`CacheNone`](/docs/api/hydrogen/utilities/cachenone), [`CacheShort`](/docs/api/hydrogen/utilities/cacheshort), [`CacheLong`](/docs/api/hydrogen/utilities/cachelong). */ - cache?: CachingStrategy; + cacheStrategy?: CachingStrategy; /** The cache key for this fetch */ cacheKey?: CacheKey; /** Useful to avoid e.g. caching a successful response that contains an error in the body */ @@ -62,12 +62,12 @@ export function createWithCache( return { run: ( - {cacheKey, strategy, shouldCacheResult}: WithCacheRunOptions, + {cacheKey, cacheStrategy, shouldCacheResult}: WithCacheRunOptions, fn: ({addDebugData}: CacheActionFunctionParam) => T | Promise, ): Promise => { return runWithCache(cacheKey, fn, { shouldCacheResult, - strategy, + strategy: cacheStrategy, cacheInstance: cache, waitUntil, debugInfo: { @@ -92,6 +92,7 @@ export function createWithCache( stackInfo: getCallerStackLine?.(), displayName: options?.displayName, }, + cache: options.cacheStrategy, ...options, }).then(([data, response]) => ({data, response})); },