@nestjs/common 9.1.3 → 9.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cache/cache.providers.js +4 -11
- package/package.json +1 -1
package/cache/cache.providers.js
CHANGED
|
@@ -13,26 +13,19 @@ const default_options_1 = require("./default-options");
|
|
|
13
13
|
function createCacheManager() {
|
|
14
14
|
return {
|
|
15
15
|
provide: cache_constants_1.CACHE_MANAGER,
|
|
16
|
-
useFactory:
|
|
16
|
+
useFactory: (options) => {
|
|
17
17
|
const cacheManager = (0, load_package_util_1.loadPackage)('cache-manager', 'CacheModule', () => require('cache-manager'));
|
|
18
18
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
19
19
|
const cacheManagerVersion = require('cache-manager/package.json').version;
|
|
20
20
|
const cacheManagerMajor = cacheManagerVersion.split('.')[0];
|
|
21
|
-
const cachingFactory =
|
|
21
|
+
const cachingFactory = (store, options) => {
|
|
22
22
|
if (cacheManagerMajor < 5) {
|
|
23
23
|
return cacheManager.caching(Object.assign(Object.assign({}, default_options_1.defaultCacheOptions), Object.assign(Object.assign({}, options), { store })));
|
|
24
24
|
}
|
|
25
|
-
|
|
26
|
-
if (typeof store === 'object' && 'create' in store) {
|
|
27
|
-
cache = store.create;
|
|
28
|
-
}
|
|
29
|
-
else if (typeof store === 'function') {
|
|
30
|
-
cache = store;
|
|
31
|
-
}
|
|
32
|
-
return cacheManager.caching(cache, Object.assign(Object.assign({}, default_options_1.defaultCacheOptions), options));
|
|
25
|
+
return cacheManager.caching(store !== null && store !== void 0 ? store : 'memory', Object.assign(Object.assign({}, default_options_1.defaultCacheOptions), options));
|
|
33
26
|
};
|
|
34
27
|
return Array.isArray(options)
|
|
35
|
-
? cacheManager.multiCaching(
|
|
28
|
+
? cacheManager.multiCaching(options.map(option => cachingFactory(options.store, option)))
|
|
36
29
|
: cachingFactory(options.store, options);
|
|
37
30
|
},
|
|
38
31
|
inject: [cache_module_definition_1.MODULE_OPTIONS_TOKEN],
|