@mondart/nestjs-common-module 2.2.1 → 2.2.3
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.
|
@@ -2,8 +2,22 @@ import { Cache } from 'cache-manager';
|
|
|
2
2
|
export declare class CachingService {
|
|
3
3
|
private cacheManager;
|
|
4
4
|
constructor(cacheManager: Cache);
|
|
5
|
-
|
|
5
|
+
getStores(): import("keyv").Keyv<any>[];
|
|
6
6
|
get<T>(key: string): Promise<T | undefined>;
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
getMany<T>(keys: string[]): Promise<T[] | undefined>;
|
|
8
|
+
set<T>(key: string, value: T, ttlSeconds?: number): Promise<string>;
|
|
9
|
+
setMany<T>(list: {
|
|
10
|
+
key: string;
|
|
11
|
+
value: T;
|
|
12
|
+
ttlSeconds?: number;
|
|
13
|
+
}[]): Promise<{
|
|
14
|
+
key: string;
|
|
15
|
+
value: string;
|
|
16
|
+
ttl?: number;
|
|
17
|
+
}[]>;
|
|
18
|
+
del(key: string): Promise<boolean>;
|
|
19
|
+
delMany(keys: string[]): Promise<boolean>;
|
|
20
|
+
clear(): Promise<boolean>;
|
|
21
|
+
has(key: string): Promise<boolean>;
|
|
22
|
+
ttl(key: string): Promise<number | undefined>;
|
|
9
23
|
}
|
|
@@ -19,7 +19,7 @@ let CachingService = class CachingService {
|
|
|
19
19
|
constructor(cacheManager) {
|
|
20
20
|
this.cacheManager = cacheManager;
|
|
21
21
|
}
|
|
22
|
-
|
|
22
|
+
getStores() {
|
|
23
23
|
return this.cacheManager.stores;
|
|
24
24
|
}
|
|
25
25
|
async get(key) {
|
|
@@ -29,11 +29,38 @@ let CachingService = class CachingService {
|
|
|
29
29
|
}
|
|
30
30
|
return undefined;
|
|
31
31
|
}
|
|
32
|
+
async getMany(keys) {
|
|
33
|
+
const results = await this.cacheManager.mget(keys);
|
|
34
|
+
if (results?.length) {
|
|
35
|
+
return results.map((result) => JSON.parse(result));
|
|
36
|
+
}
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
32
39
|
async set(key, value, ttlSeconds) {
|
|
33
|
-
await this.cacheManager.set(key, JSON.stringify(value), ttlSeconds * 1000);
|
|
40
|
+
return await this.cacheManager.set(key, JSON.stringify(value), ttlSeconds ? ttlSeconds * 1000 : undefined);
|
|
41
|
+
}
|
|
42
|
+
async setMany(list) {
|
|
43
|
+
const valuesToSet = list.map((item) => ({
|
|
44
|
+
key: item.key,
|
|
45
|
+
value: JSON.stringify(item.value),
|
|
46
|
+
ttl: item?.ttlSeconds ? item.ttlSeconds * 1000 : undefined,
|
|
47
|
+
}));
|
|
48
|
+
return await this.cacheManager.mset(valuesToSet);
|
|
34
49
|
}
|
|
35
50
|
async del(key) {
|
|
36
|
-
await this.cacheManager.del(key);
|
|
51
|
+
return await this.cacheManager.del(key);
|
|
52
|
+
}
|
|
53
|
+
async delMany(keys) {
|
|
54
|
+
return await this.cacheManager.mdel(keys);
|
|
55
|
+
}
|
|
56
|
+
async clear() {
|
|
57
|
+
return await this.cacheManager.clear();
|
|
58
|
+
}
|
|
59
|
+
async has(key) {
|
|
60
|
+
return (await this.cacheManager.get(key)) !== undefined;
|
|
61
|
+
}
|
|
62
|
+
async ttl(key) {
|
|
63
|
+
return this.cacheManager.ttl(key);
|
|
37
64
|
}
|
|
38
65
|
};
|
|
39
66
|
exports.CachingService = CachingService;
|