Skip to content

Commit

Permalink
Move to cache-manager-ioredis-yet
Browse files Browse the repository at this point in the history
  • Loading branch information
thgreasi committed Oct 26, 2022
1 parent 3f8fea3 commit 7c4f9d0
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 175 deletions.
153 changes: 14 additions & 139 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@
"@sentry/node": "^7.12.1",
"@types/basic-auth": "^1.1.3",
"@types/bluebird": "^3.5.36",
"@types/cache-manager": "^4.0.2",
"@types/cache-manager-ioredis": "^2.0.2",
"@types/common-tags": "^1.8.1",
"@types/compressible": "^2.0.0",
"@types/compression-next": "^1.0.0",
Expand Down Expand Up @@ -75,7 +73,7 @@
"bluebird": "^3.7.2",
"body-parser": "^1.20.0",
"cache-manager": "^5.0.0",
"cache-manager-ioredis": "^2.1.0",
"cache-manager-ioredis-yet": "^1.0.0",
"common-tags": "^1.8.2",
"compressible": "^2.0.18",
"compression": "^1.7.4",
Expand Down
13 changes: 11 additions & 2 deletions src/infra/cache/multi-level-memoizee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export function multiCacheMemoizee<
};

const multiCacheOpts: Parameters<typeof createMultiLevelStore>[1] = {
default: { ...convertToMultiStoreOpts(opts), isCacheableValue: () => true },
default: { ...convertToMultiStoreOpts(opts), isCacheable: () => true },
global: convertToMultiStoreOpts({ ...opts, ...sharedCacheOpts }),
};

Expand Down Expand Up @@ -146,7 +146,16 @@ function multiCache<T extends (...args: any[]) => Promise<Defined | undefined>>(
const valueToCache = await fn(...args);
// Some caches (eg redis) cannot handle caching undefined/null so we convert it to the `undefinedAs` proxy value
// which will be used when storing in the cache and then convert it back to undefined when retrieving from the cache
return valueToCache === undefined ? undefinedAs : valueToCache;
if (valueToCache === undefined) {
// Just to make TS happy, since the typings should already be protecting us.
if (undefinedAs === undefined) {
throw new Error(
'Multilevel cache detected undefined value while the undefinedAs was not defined',
);
}
return undefinedAs;
}
return valueToCache;
});
return valueFromCache === undefinedAs ? undefined : valueFromCache;
};
Expand Down
Loading

0 comments on commit 7c4f9d0

Please sign in to comment.