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

fix(cache): use passed store object #10591

Merged
merged 1 commit into from Nov 29, 2022
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion integration/cache/src/multi-store/multi-store.module.ts
@@ -1,5 +1,5 @@
import { CacheModule, Module } from '@nestjs/common';
import * as redisStore from 'cache-manager-redis-store';
import { redisStore } from 'cache-manager-redis-store';
import { MultiStoreController } from './multi-store.controller';

@Module({
Expand Down
15 changes: 11 additions & 4 deletions packages/common/cache/cache.providers.ts
Expand Up @@ -3,7 +3,10 @@ import { loadPackage } from '../utils/load-package.util';
import { CACHE_MANAGER } from './cache.constants';
import { MODULE_OPTIONS_TOKEN } from './cache.module-definition';
import { defaultCacheOptions } from './default-options';
import { CacheManagerOptions } from './interfaces/cache-manager.interface';
import {
CacheManagerOptions,
CacheStore,
} from './interfaces/cache-manager.interface';

/**
* Creates a CacheManager Provider.
Expand All @@ -28,10 +31,14 @@ export function createCacheManager(): Provider {
...{ ...options, store },
});
}
let cache: string | Function = 'memory';
let cache: string | Function | CacheStore = 'memory';
defaultCacheOptions.ttl *= 1000;
if (typeof store === 'object' && 'create' in store) {
cache = store.create;
if (typeof store === 'object') {
if ('create' in store) {
cache = store.create;
} else {
cache = store;
}
} else if (typeof store === 'function') {
cache = store;
}
Expand Down