Skip to content

Commit

Permalink
Align on param naming for cacheStrategy
Browse files Browse the repository at this point in the history
  • Loading branch information
rbshop committed Oct 11, 2024
1 parent 72c9721 commit 4569b1e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
4 changes: 2 additions & 2 deletions packages/hydrogen/src/cache/create-with-cache.example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) => {
Expand Down
20 changes: 10 additions & 10 deletions packages/hydrogen/src/cache/create-with-cache.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('createWithCache', () => {
withCache.run(
{
cacheKey: KEY,
strategy: CacheNone(),
cacheStrategy: CacheNone(),
shouldCacheResult: () => true,
},
actionFn,
Expand All @@ -54,7 +54,7 @@ describe('createWithCache', () => {
withCache.run(
{
cacheKey: KEY,
strategy: CacheNone(),
cacheStrategy: CacheNone(),
shouldCacheResult: () => true,
},
actionFn,
Expand All @@ -78,7 +78,7 @@ describe('createWithCache', () => {
withCache.run(
{
cacheKey: KEY,
strategy: CacheShort(),
cacheStrategy: CacheShort(),
shouldCacheResult: () => true,
},
actionFn,
Expand All @@ -96,7 +96,7 @@ describe('createWithCache', () => {
withCache.run(
{
cacheKey: KEY,
strategy,
cacheStrategy: strategy,
shouldCacheResult: (v) => v !== VALUE,
},
actionFn,
Expand All @@ -111,7 +111,7 @@ describe('createWithCache', () => {
withCache.run(
{
cacheKey: KEY,
strategy,
cacheStrategy: strategy,
shouldCacheResult: (v) => v !== VALUE,
},
actionFn,
Expand All @@ -130,7 +130,7 @@ describe('createWithCache', () => {
withCache.run(
{
cacheKey: KEY,
strategy,
cacheStrategy: strategy,
shouldCacheResult: () => true,
},
actionFn,
Expand All @@ -150,7 +150,7 @@ describe('createWithCache', () => {
withCache.run(
{
cacheKey: KEY,
strategy,
cacheStrategy: strategy,
shouldCacheResult: () => true,
},
actionFn,
Expand All @@ -171,7 +171,7 @@ describe('createWithCache', () => {
withCache.run(
{
cacheKey: KEY,
strategy,
cacheStrategy: strategy,
shouldCacheResult: () => true,
},
actionFn,
Expand All @@ -191,7 +191,7 @@ describe('createWithCache', () => {
withCache.run(
{
cacheKey: KEY,
strategy,
cacheStrategy: strategy,
shouldCacheResult: () => true,
},
actionFn,
Expand All @@ -217,7 +217,7 @@ describe('createWithCache', () => {
withCache.run(
{
cacheKey: KEY,
strategy,
cacheStrategy: strategy,
shouldCacheResult: () => true,
},
actionFn,
Expand Down
9 changes: 5 additions & 4 deletions packages/hydrogen/src/cache/create-with-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type WithCacheRunOptions<T> = {
* 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;
};
Expand All @@ -36,7 +36,7 @@ type WithCacheFetchOptions<T> = {
* 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 */
Expand All @@ -62,12 +62,12 @@ export function createWithCache(

return {
run: <T>(
{cacheKey, strategy, shouldCacheResult}: WithCacheRunOptions<T>,
{cacheKey, cacheStrategy, shouldCacheResult}: WithCacheRunOptions<T>,
fn: ({addDebugData}: CacheActionFunctionParam) => T | Promise<T>,
): Promise<T> => {
return runWithCache(cacheKey, fn, {
shouldCacheResult,
strategy,
strategy: cacheStrategy,
cacheInstance: cache,
waitUntil,
debugInfo: {
Expand All @@ -92,6 +92,7 @@ export function createWithCache(
stackInfo: getCallerStackLine?.(),
displayName: options?.displayName,
},
cache: options.cacheStrategy,
...options,
}).then(([data, response]) => ({data, response}));
},
Expand Down

0 comments on commit 4569b1e

Please sign in to comment.