Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "fix: update factory to account for old v4 syntax for cache stores" #10368

Merged
merged 1 commit into from
Oct 5, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 5 additions & 13 deletions packages/common/cache/cache.providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,40 +13,32 @@ import { CacheManagerOptions } from './interfaces/cache-manager.interface';
export function createCacheManager(): Provider {
return {
provide: CACHE_MANAGER,
useFactory: async (options: CacheManagerOptions) => {
useFactory: (options: CacheManagerOptions) => {
const cacheManager = loadPackage('cache-manager', 'CacheModule', () =>
require('cache-manager'),
);
// eslint-disable-next-line @typescript-eslint/no-var-requires
const cacheManagerVersion = require('cache-manager/package.json').version;
const cacheManagerMajor = cacheManagerVersion.split('.')[0];
const cachingFactory = async (
const cachingFactory = (
store: CacheManagerOptions['store'],
options: Omit<CacheManagerOptions, 'store'>,
): Promise<Record<string, any>> => {
): Record<string, any> => {
if (cacheManagerMajor < 5) {
return cacheManager.caching({
...defaultCacheOptions,
...{ ...options, store },
});
}
let cache: string | Function = 'memory';
if (typeof store === 'object' && 'create' in store) {
cache = store.create;
} else if (typeof store === 'function') {
cache = store;
}
return cacheManager.caching(cache, {
return cacheManager.caching(store ?? 'memory', {
...defaultCacheOptions,
...options,
});
};

return Array.isArray(options)
? cacheManager.multiCaching(
await Promise.all(
options.map(option => cachingFactory(option.store, option)),
),
options.map(option => cachingFactory(options.store, option)),
)
: cachingFactory(options.store, options);
},
Expand Down