@seidor-cloud-produtos/orbit-backend-lib 1.101.37 → 1.101.38

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,10 +6,6 @@ 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
- };
13
9
  export declare abstract class Cache {
14
10
  protected client: CacheClient;
15
11
  protected elegibleClients: CacheClient[];
@@ -29,5 +25,5 @@ export declare abstract class Cache {
29
25
  isRunning(options?: MethodOptions, isContingency?: boolean): Promise<boolean>;
30
26
  close(options?: MethodOptions): Promise<void>;
31
27
  protected handleException(e: Error): Promise<void>;
32
- getOrFetchAndCache<T>(keyCache: string, expiration: number | undefined, fetch: FetchParams<T>, options?: MethodOptions): Promise<T | undefined>;
28
+ getOrFetchAndCache<T>(keyCache: string, expiration: number | undefined, promise: () => Promise<T>, options?: MethodOptions): Promise<T | undefined>;
33
29
  }
@@ -166,13 +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);
169
+ async getOrFetchAndCache(keyCache, expiration = this.DEFAULT_EXPIRATION_SECONDS, promise, options) {
170
+ let data = await this.get(keyCache, options);
171
+ if (!data) {
172
+ data = await promise();
173
+ this.set(keyCache, data, expiration, options);
174
174
  }
175
- return cached;
175
+ return data;
176
176
  }
177
177
  }
178
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.37",
3
+ "version": "1.101.38",
4
4
  "description": "Internal lib for backend components",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",