Skip to content

Commit 0ee84c4

Browse files
Merge pull request #10591 from Leichtwind/master
fix(cache): use passed store object
2 parents ef917e0 + 2983f54 commit 0ee84c4

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

integration/cache/src/multi-store/multi-store.module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { CacheModule, Module } from '@nestjs/common';
2-
import * as redisStore from 'cache-manager-redis-store';
2+
import { redisStore } from 'cache-manager-redis-store';
33
import { MultiStoreController } from './multi-store.controller';
44

55
@Module({

packages/common/cache/cache.providers.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ import { loadPackage } from '../utils/load-package.util';
33
import { CACHE_MANAGER } from './cache.constants';
44
import { MODULE_OPTIONS_TOKEN } from './cache.module-definition';
55
import { defaultCacheOptions } from './default-options';
6-
import { CacheManagerOptions } from './interfaces/cache-manager.interface';
6+
import {
7+
CacheManagerOptions,
8+
CacheStore,
9+
} from './interfaces/cache-manager.interface';
710

811
/**
912
* Creates a CacheManager Provider.
@@ -28,10 +31,14 @@ export function createCacheManager(): Provider {
2831
...{ ...options, store },
2932
});
3033
}
31-
let cache: string | Function = 'memory';
34+
let cache: string | Function | CacheStore = 'memory';
3235
defaultCacheOptions.ttl *= 1000;
33-
if (typeof store === 'object' && 'create' in store) {
34-
cache = store.create;
36+
if (typeof store === 'object') {
37+
if ('create' in store) {
38+
cache = store.create;
39+
} else {
40+
cache = store;
41+
}
3542
} else if (typeof store === 'function') {
3643
cache = store;
3744
}

0 commit comments

Comments
 (0)