@seidor-cloud-produtos/orbit-backend-lib 1.101.35 → 1.101.37
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.
|
@@ -6,6 +6,10 @@ export type CacheOptions = {
|
|
|
6
6
|
throwOnError?: boolean;
|
|
7
7
|
contingencyClients?: CacheClient[];
|
|
8
8
|
};
|
|
9
|
+
export type FetchParams<T = unknown, A extends any[] = any[]> = {
|
|
10
|
+
params: A;
|
|
11
|
+
fetch: (...args: A) => Promise<T>;
|
|
12
|
+
};
|
|
9
13
|
export declare abstract class Cache {
|
|
10
14
|
protected client: CacheClient;
|
|
11
15
|
protected elegibleClients: CacheClient[];
|
|
@@ -25,4 +29,5 @@ export declare abstract class Cache {
|
|
|
25
29
|
isRunning(options?: MethodOptions, isContingency?: boolean): Promise<boolean>;
|
|
26
30
|
close(options?: MethodOptions): Promise<void>;
|
|
27
31
|
protected handleException(e: Error): Promise<void>;
|
|
32
|
+
getOrFetchAndCache<T>(keyCache: string, expiration: number | undefined, fetch: FetchParams<T>, options?: MethodOptions): Promise<T | undefined>;
|
|
28
33
|
}
|
|
@@ -166,5 +166,13 @@ class Cache {
|
|
|
166
166
|
catch { }
|
|
167
167
|
throw e;
|
|
168
168
|
}
|
|
169
|
+
async getOrFetchAndCache(keyCache, expiration = this.DEFAULT_EXPIRATION_SECONDS, fetch, options) {
|
|
170
|
+
let cached = await this.get(keyCache, options);
|
|
171
|
+
if (!cached) {
|
|
172
|
+
cached = await fetch.fetch(...fetch.params);
|
|
173
|
+
this.set(keyCache, cached, expiration, options);
|
|
174
|
+
}
|
|
175
|
+
return cached;
|
|
176
|
+
}
|
|
169
177
|
}
|
|
170
178
|
exports.Cache = Cache;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@seidor-cloud-produtos/orbit-backend-lib",
|
|
3
|
-
"version": "1.101.
|
|
3
|
+
"version": "1.101.37",
|
|
4
4
|
"description": "Internal lib for backend components",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -80,7 +80,7 @@
|
|
|
80
80
|
"dependencies": {
|
|
81
81
|
"@fastify/cors": "8.3.0",
|
|
82
82
|
"@nestjs/common": "8.4.7",
|
|
83
|
-
"amqplib": "0.10.
|
|
83
|
+
"amqplib": "0.10.9",
|
|
84
84
|
"axios": "1.8.2",
|
|
85
85
|
"compression": "1.7.4",
|
|
86
86
|
"discord.js": "14.16.3",
|