@mondart/nestjs-common-module 1.1.49 → 1.1.51
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.
|
@@ -3,5 +3,6 @@ import { CachingModuleAsyncOptions, CachingModuleOptions } from './caching.inter
|
|
|
3
3
|
export declare class CachingModule {
|
|
4
4
|
static register(options: CachingModuleOptions): DynamicModule;
|
|
5
5
|
static registerAsync(options: CachingModuleAsyncOptions): DynamicModule;
|
|
6
|
+
private static createAsyncOptionsProvider;
|
|
6
7
|
private static createAsyncProviders;
|
|
7
8
|
}
|
|
@@ -12,20 +12,24 @@ const common_1 = require("@nestjs/common");
|
|
|
12
12
|
const caching_service_1 = require("./caching.service");
|
|
13
13
|
const cache_manager_1 = require("@nestjs/cache-manager");
|
|
14
14
|
const caching_interface_1 = require("./caching.interface");
|
|
15
|
-
const
|
|
15
|
+
const cache_manager_ioredis_yet_1 = require("cache-manager-ioredis-yet");
|
|
16
16
|
let CachingModule = CachingModule_1 = class CachingModule {
|
|
17
17
|
static register(options) {
|
|
18
|
-
const cacheModuleOptions = {
|
|
19
|
-
store: redisStore,
|
|
20
|
-
ttl: Number(options.ttl),
|
|
21
|
-
host: options.host,
|
|
22
|
-
port: Number(options.port),
|
|
23
|
-
password: options.password,
|
|
24
|
-
max: 10000,
|
|
25
|
-
};
|
|
26
18
|
return {
|
|
27
19
|
module: CachingModule_1,
|
|
28
|
-
imports: [
|
|
20
|
+
imports: [
|
|
21
|
+
cache_manager_1.CacheModule.register({
|
|
22
|
+
isGlobal: true,
|
|
23
|
+
useFactory: async (cachingOptions) => ({
|
|
24
|
+
store: await (0, cache_manager_ioredis_yet_1.redisStore)({
|
|
25
|
+
host: cachingOptions.host,
|
|
26
|
+
port: cachingOptions.port,
|
|
27
|
+
password: cachingOptions.password,
|
|
28
|
+
ttl: cachingOptions.ttl,
|
|
29
|
+
}),
|
|
30
|
+
}),
|
|
31
|
+
}),
|
|
32
|
+
],
|
|
29
33
|
providers: [
|
|
30
34
|
{
|
|
31
35
|
provide: caching_interface_1.CACHING_MODULE_OPTIONS,
|
|
@@ -37,27 +41,44 @@ let CachingModule = CachingModule_1 = class CachingModule {
|
|
|
37
41
|
};
|
|
38
42
|
}
|
|
39
43
|
static registerAsync(options) {
|
|
44
|
+
const asyncOptionsProvider = this.createAsyncOptionsProvider(options);
|
|
40
45
|
return {
|
|
41
46
|
module: CachingModule_1,
|
|
42
47
|
imports: [
|
|
43
48
|
...(options.imports || []),
|
|
49
|
+
asyncOptionsProvider,
|
|
44
50
|
cache_manager_1.CacheModule.registerAsync({
|
|
45
|
-
imports:
|
|
51
|
+
imports: [asyncOptionsProvider],
|
|
46
52
|
useFactory: async (cachingOptions) => ({
|
|
47
|
-
store: redisStore
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
53
|
+
store: await (0, cache_manager_ioredis_yet_1.redisStore)({
|
|
54
|
+
host: cachingOptions.host,
|
|
55
|
+
port: cachingOptions.port,
|
|
56
|
+
password: cachingOptions.password,
|
|
57
|
+
ttl: cachingOptions.ttl,
|
|
58
|
+
}),
|
|
52
59
|
max: 10000,
|
|
53
60
|
}),
|
|
54
61
|
inject: [caching_interface_1.CACHING_MODULE_OPTIONS],
|
|
55
62
|
}),
|
|
56
63
|
],
|
|
57
|
-
providers: [
|
|
64
|
+
providers: [
|
|
65
|
+
{
|
|
66
|
+
provide: caching_service_1.CachingService,
|
|
67
|
+
useFactory: (cacheManager) => new caching_service_1.CachingService(cacheManager),
|
|
68
|
+
inject: [cache_manager_1.CACHE_MANAGER],
|
|
69
|
+
},
|
|
70
|
+
],
|
|
58
71
|
exports: [caching_service_1.CachingService, cache_manager_1.CacheModule],
|
|
59
72
|
};
|
|
60
73
|
}
|
|
74
|
+
static createAsyncOptionsProvider(options) {
|
|
75
|
+
const providers = this.createAsyncProviders(options);
|
|
76
|
+
return {
|
|
77
|
+
module: CachingModule_1,
|
|
78
|
+
providers,
|
|
79
|
+
exports: [caching_interface_1.CACHING_MODULE_OPTIONS],
|
|
80
|
+
};
|
|
81
|
+
}
|
|
61
82
|
static createAsyncProviders(options) {
|
|
62
83
|
if (options.useFactory) {
|
|
63
84
|
return [
|