Skip to content

Commit

Permalink
Merge pull request #10591 from Leichtwind/master
Browse files Browse the repository at this point in the history
fix(cache): use passed store object
  • Loading branch information
kamilmysliwiec authored Nov 29, 2022
2 parents ef917e0 + 2983f54 commit 0ee84c4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion integration/cache/src/multi-store/multi-store.module.ts
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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

0 comments on commit 0ee84c4

Please sign in to comment.