fix(package): project setup

This commit is contained in:
2018-07-12 23:52:06 +02:00
parent c2740ca25b
commit 073d792497
7 changed files with 705 additions and 46 deletions

View File

@@ -7,13 +7,17 @@ export class SmartCache {
async cacheReturn(asyncCachedFuncArg: () => Promise<any>, cacheDuration: number = 5000) {
let callStack: string = new plugins.smarterror.SmartError('').cleanFullStack;
let callHash = plugins.nodehash.sha256FromStringSync(callStack);
console.log(callHash);
if(this._cacheManager.cacheExists(callHash) && await this._cacheManager.waitForCacheReady(callHash) && this._cacheManager.stillValid(callHash)) {
if (
this._cacheManager.cacheExists(callHash) &&
(await this._cacheManager.waitForCacheReady(callHash)) &&
this._cacheManager.stillValid(callHash)
) {
return this._cacheManager.getCache(callHash).cachedObject;
} else {
this._cacheManager.announceCache(callHash, cacheDuration);
let newCachedObject = await asyncCachedFuncArg()
let newCachedObject = await asyncCachedFuncArg();
this._cacheManager.setCache(callHash, newCachedObject, cacheDuration);
return newCachedObject;
}