@seidor-cloud-produtos/orbit-backend-lib 1.101.36 → 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.
@@ -25,4 +25,5 @@ export declare abstract class Cache {
25
25
  isRunning(options?: MethodOptions, isContingency?: boolean): Promise<boolean>;
26
26
  close(options?: MethodOptions): Promise<void>;
27
27
  protected handleException(e: Error): Promise<void>;
28
+ getOrFetchAndCache<T>(keyCache: string, expiration: number | undefined, promise: () => Promise<T>, options?: MethodOptions): Promise<T | undefined>;
28
29
  }
@@ -166,5 +166,13 @@ class Cache {
166
166
  catch { }
167
167
  throw e;
168
168
  }
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
+ }
175
+ return data;
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.36",
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",