Compare commits
21 Commits
Author | SHA1 | Date | |
---|---|---|---|
dc5a93b3a2 | |||
51c1759961 | |||
b5667be823 | |||
f147d48655 | |||
9eec43044d | |||
4df1274094 | |||
1edda548a1 | |||
c94b5e0009 | |||
fd5f5e357c | |||
57f50ef507 | |||
58bcf0cea2 | |||
bf2d3f661e | |||
eef3fd7c1f | |||
219944218c | |||
00364d261a | |||
04aa6b2fb5 | |||
e113ce5e8e | |||
3e2086fe34 | |||
f9e7204294 | |||
0223581938 | |||
073d792497 |
18
.gitignore
vendored
18
.gitignore
vendored
@@ -1,6 +1,22 @@
|
|||||||
.nogit/
|
.nogit/
|
||||||
node_modules/
|
|
||||||
|
# artifacts
|
||||||
coverage/
|
coverage/
|
||||||
public/
|
public/
|
||||||
pages/
|
pages/
|
||||||
|
|
||||||
|
# installs
|
||||||
|
node_modules/
|
||||||
|
|
||||||
|
# caches
|
||||||
.yarn/
|
.yarn/
|
||||||
|
.cache/
|
||||||
|
.rpt2_cache
|
||||||
|
|
||||||
|
# builds
|
||||||
|
dist/
|
||||||
|
dist_web/
|
||||||
|
dist_serve/
|
||||||
|
dist_ts_web/
|
||||||
|
|
||||||
|
# custom
|
131
.gitlab-ci.yml
131
.gitlab-ci.yml
@@ -1,16 +1,16 @@
|
|||||||
# gitzone standard
|
# gitzone ci_default
|
||||||
image: hosttoday/ht-docker-node:npmci
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
|
|
||||||
cache:
|
cache:
|
||||||
paths:
|
paths:
|
||||||
- .npmci_cache/
|
- .npmci_cache/
|
||||||
key: "$CI_BUILD_STAGE"
|
key: '$CI_BUILD_STAGE'
|
||||||
|
|
||||||
stages:
|
stages:
|
||||||
- security
|
- security
|
||||||
- test
|
- test
|
||||||
- release
|
- release
|
||||||
- metadata
|
- metadata
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# security stage
|
# security stage
|
||||||
@@ -18,108 +18,103 @@ stages:
|
|||||||
mirror:
|
mirror:
|
||||||
stage: security
|
stage: security
|
||||||
script:
|
script:
|
||||||
- npmci git mirror
|
- npmci git mirror
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- notpriv
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
snyk:
|
snyk:
|
||||||
|
image: registry.gitlab.com/hosttoday/ht-docker-node:snyk
|
||||||
stage: security
|
stage: security
|
||||||
script:
|
script:
|
||||||
- npmci command npm install -g snyk
|
- npmci npm prepare
|
||||||
- npmci command npm install --ignore-scripts
|
- npmci command npm install --ignore-scripts
|
||||||
- npmci command snyk test
|
- npmci command snyk test
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- notpriv
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# test stage
|
# test stage
|
||||||
# ====================
|
# ====================
|
||||||
testLEGACY:
|
|
||||||
stage: test
|
|
||||||
script:
|
|
||||||
- npmci node install legacy
|
|
||||||
- npmci npm install
|
|
||||||
- npmci npm test
|
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
allow_failure: true
|
|
||||||
|
|
||||||
testLTS:
|
testStable:
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
- npmci node install lts
|
- npmci npm prepare
|
||||||
- npmci npm install
|
- npmci node install stable
|
||||||
- npmci npm test
|
- npmci npm install
|
||||||
|
- npmci npm test
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- notpriv
|
- docker
|
||||||
|
- priv
|
||||||
|
|
||||||
testSTABLE:
|
testBuild:
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
- npmci node install stable
|
- npmci npm prepare
|
||||||
- npmci npm install
|
- npmci node install stable
|
||||||
- npmci npm test
|
- npmci npm install
|
||||||
|
- npmci command npm run build
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- notpriv
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
release:
|
release:
|
||||||
stage: release
|
stage: release
|
||||||
script:
|
script:
|
||||||
- npmci node install stable
|
- npmci node install stable
|
||||||
- npmci npm publish
|
- npmci npm publish
|
||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- notpriv
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# metadata stage
|
# metadata stage
|
||||||
# ====================
|
# ====================
|
||||||
codequality:
|
codequality:
|
||||||
stage: metadata
|
stage: metadata
|
||||||
image: docker:stable
|
|
||||||
allow_failure: true
|
allow_failure: true
|
||||||
services:
|
|
||||||
- docker:stable-dind
|
|
||||||
script:
|
script:
|
||||||
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
|
- npmci command npm install -g tslint typescript
|
||||||
- docker run
|
- npmci npm prepare
|
||||||
--env SOURCE_CODE="$PWD"
|
- npmci npm install
|
||||||
--volume "$PWD":/code
|
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
||||||
--volume /var/run/docker.sock:/var/run/docker.sock
|
|
||||||
"registry.gitlab.com/gitlab-org/security-products/codequality:$SP_VERSION" /code
|
|
||||||
artifacts:
|
|
||||||
paths: [codeclimate.json]
|
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- priv
|
- docker
|
||||||
|
- priv
|
||||||
|
|
||||||
trigger:
|
trigger:
|
||||||
stage: metadata
|
stage: metadata
|
||||||
script:
|
script:
|
||||||
- npmci trigger
|
- npmci trigger
|
||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- notpriv
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
pages:
|
pages:
|
||||||
image: hosttoday/ht-docker-node:npmci
|
|
||||||
stage: metadata
|
stage: metadata
|
||||||
script:
|
script:
|
||||||
- npmci command npm install -g npmpage
|
- npmci node install lts
|
||||||
- npmci command npmpage
|
- npmci command npm install -g @gitzone/tsdoc
|
||||||
|
- npmci npm prepare
|
||||||
|
- npmci npm install
|
||||||
|
- npmci command tsdoc
|
||||||
tags:
|
tags:
|
||||||
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
- notpriv
|
||||||
only:
|
only:
|
||||||
@@ -127,15 +122,5 @@ pages:
|
|||||||
artifacts:
|
artifacts:
|
||||||
expire_in: 1 week
|
expire_in: 1 week
|
||||||
paths:
|
paths:
|
||||||
- public
|
- public
|
||||||
allow_failure: true
|
|
||||||
|
|
||||||
windowsCompatibility:
|
|
||||||
image: stefanscherer/node-windows:10-build-tools
|
|
||||||
stage: metadata
|
|
||||||
script:
|
|
||||||
- npm install & npm test
|
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
|
||||||
tags:
|
|
||||||
- windows
|
|
||||||
allow_failure: true
|
allow_failure: true
|
||||||
|
29
.vscode/launch.json
vendored
Normal file
29
.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
{
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "current file",
|
||||||
|
"type": "node",
|
||||||
|
"request": "launch",
|
||||||
|
"args": [
|
||||||
|
"${relativeFile}"
|
||||||
|
],
|
||||||
|
"runtimeArgs": ["-r", "@gitzone/tsrun"],
|
||||||
|
"cwd": "${workspaceRoot}",
|
||||||
|
"protocol": "inspector",
|
||||||
|
"internalConsoleOptions": "openOnSessionStart"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "test.ts",
|
||||||
|
"type": "node",
|
||||||
|
"request": "launch",
|
||||||
|
"args": [
|
||||||
|
"test/test.ts"
|
||||||
|
],
|
||||||
|
"runtimeArgs": ["-r", "@gitzone/tsrun"],
|
||||||
|
"cwd": "${workspaceRoot}",
|
||||||
|
"protocol": "inspector",
|
||||||
|
"internalConsoleOptions": "openOnSessionStart"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
26
.vscode/settings.json
vendored
Normal file
26
.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
{
|
||||||
|
"json.schemas": [
|
||||||
|
{
|
||||||
|
"fileMatch": ["/npmextra.json"],
|
||||||
|
"schema": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"npmci": {
|
||||||
|
"type": "object",
|
||||||
|
"description": "settings for npmci"
|
||||||
|
},
|
||||||
|
"gitzone": {
|
||||||
|
"type": "object",
|
||||||
|
"description": "settings for gitzone",
|
||||||
|
"properties": {
|
||||||
|
"projectType": {
|
||||||
|
"type": "string",
|
||||||
|
"enum": ["website", "element", "service", "npm"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
@@ -1 +0,0 @@
|
|||||||
.gitignore: ../gitignore/
|
|
@@ -1,8 +1,17 @@
|
|||||||
{
|
{
|
||||||
"npmci": {
|
"npmci": {
|
||||||
"npmGlobalTools": [
|
"npmGlobalTools": [],
|
||||||
"@gitzone/npmts",
|
"npmAccessLevel": "public"
|
||||||
"ts-node"
|
},
|
||||||
]
|
"gitzone": {
|
||||||
|
"projectType": "npm",
|
||||||
|
"module": {
|
||||||
|
"githost": "gitlab.com",
|
||||||
|
"gitscope": "pushrocks",
|
||||||
|
"gitrepo": "smartcache",
|
||||||
|
"shortDescription": "cache things in smart ways",
|
||||||
|
"npmPackagename": "@pushrocks/smartcache",
|
||||||
|
"license": "MIT"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
1688
package-lock.json
generated
1688
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
37
package.json
37
package.json
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "smartcache",
|
"name": "@pushrocks/smartcache",
|
||||||
"version": "1.0.2",
|
"version": "1.0.13",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "cache things in smart ways",
|
"description": "cache things in smart ways",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
@@ -8,17 +8,34 @@
|
|||||||
"author": "Lossless GmbH",
|
"author": "Lossless GmbH",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(tsrun test/test.ts)",
|
"test": "(tstest test/)",
|
||||||
"build": "(npmts)"
|
"build": "(tsbuild)"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "^10.5.2"
|
"@gitzone/tsbuild": "^2.1.17",
|
||||||
|
"@gitzone/tsrun": "^1.2.8",
|
||||||
|
"@gitzone/tstest": "^1.0.28",
|
||||||
|
"@pushrocks/tapbundle": "^3.2.0",
|
||||||
|
"@types/node": "^13.7.0",
|
||||||
|
"tslint": "^6.0.0",
|
||||||
|
"tslint-config-prettier": "^1.18.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/smartdelay": "^2.0.1",
|
"@pushrocks/smartdelay": "^2.0.6",
|
||||||
"@pushrocks/smarterror": "^2.0.1",
|
"@pushrocks/smarterror": "^2.0.1",
|
||||||
"@pushrocks/smartpromise": "^2.0.5",
|
"@pushrocks/smarthash": "^2.1.6",
|
||||||
"@pushrocks/smarttime": "^2.0.1",
|
"@pushrocks/smartpromise": "^3.0.6",
|
||||||
"nodehash": "^1.0.4"
|
"@pushrocks/smarttime": "^3.0.12"
|
||||||
}
|
},
|
||||||
|
"files": [
|
||||||
|
"ts/**/*",
|
||||||
|
"ts_web/**/*",
|
||||||
|
"dist/**/*",
|
||||||
|
"dist_web/**/*",
|
||||||
|
"dist_ts_web/**/*",
|
||||||
|
"assets/**/*",
|
||||||
|
"cli.js",
|
||||||
|
"npmextra.json",
|
||||||
|
"readme.md"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
31
readme.md
Normal file
31
readme.md
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
# @pushrocks/smartcache
|
||||||
|
cache things in smart ways
|
||||||
|
|
||||||
|
## Availabililty and Links
|
||||||
|
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartcache)
|
||||||
|
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartcache)
|
||||||
|
* [github.com (source mirror)](https://github.com/pushrocks/smartcache)
|
||||||
|
* [docs (typedoc)](https://pushrocks.gitlab.io/smartcache/)
|
||||||
|
|
||||||
|
## Status for master
|
||||||
|
[](https://gitlab.com/pushrocks/smartcache/commits/master)
|
||||||
|
[](https://gitlab.com/pushrocks/smartcache/commits/master)
|
||||||
|
[](https://www.npmjs.com/package/@pushrocks/smartcache)
|
||||||
|
[](https://snyk.io/test/npm/@pushrocks/smartcache)
|
||||||
|
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||||
|
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||||
|
[](https://prettier.io/)
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
|
||||||
|
## Contribution
|
||||||
|
|
||||||
|
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
|
||||||
|
|
||||||
|
For further information read the linked docs at the top of this readme.
|
||||||
|
|
||||||
|
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||||
|
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
|
||||||
|
|
||||||
|
[](https://maintainedby.lossless.com)
|
75
test/test.ts
75
test/test.ts
@@ -1,36 +1,51 @@
|
|||||||
// import { expect, tap } from 'tapbundle';
|
import { expect, tap } from '@pushrocks/tapbundle';
|
||||||
import * as smartcache from '../ts/index';
|
import * as smartcache from '../ts/index';
|
||||||
import * as smartdelay from '@pushrocks/smartdelay';
|
import * as smartdelay from '@pushrocks/smartdelay';
|
||||||
|
|
||||||
const smartcacheInstance = new smartcache.SmartCache();
|
let smartcacheInstance: smartcache.SmartCache;
|
||||||
const getResponse = async () => {
|
|
||||||
const response = await smartcacheInstance.cacheReturn(async () => {
|
|
||||||
console.log('function ran')
|
|
||||||
return 'hello';
|
|
||||||
}, 1000).catch(err => {
|
|
||||||
console.log(err);
|
|
||||||
});
|
|
||||||
console.log('response is:')
|
|
||||||
console.log(response);
|
|
||||||
};
|
|
||||||
|
|
||||||
const getResponse2 = async () => {
|
tap.test('should create a valid instance of SmartCache', async () => {
|
||||||
const response = await smartcacheInstance.cacheReturn(async () => {
|
smartcacheInstance = new smartcache.SmartCache();
|
||||||
console.log('function ran')
|
expect(smartcacheInstance).to.be.instanceof(smartcache.SmartCache);
|
||||||
return 'hello';
|
|
||||||
}, 1000).catch(err => {
|
|
||||||
console.log(err);
|
|
||||||
});
|
|
||||||
console.log('response is:')
|
|
||||||
console.log(response);
|
|
||||||
};
|
|
||||||
|
|
||||||
getResponse();
|
|
||||||
getResponse();
|
|
||||||
getResponse2();
|
|
||||||
getResponse2();
|
|
||||||
smartdelay.delayFor(1000).then(() => {
|
|
||||||
getResponse();
|
|
||||||
// getResponse2();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
tap.test('try to get async responses', async () => {
|
||||||
|
const getResponse = async () => {
|
||||||
|
const response = await smartcacheInstance
|
||||||
|
.cacheReturn(async () => {
|
||||||
|
console.log('function 1 ran');
|
||||||
|
return 'hello';
|
||||||
|
}, 1000)
|
||||||
|
.catch(err => {
|
||||||
|
console.log(err);
|
||||||
|
});
|
||||||
|
console.log('response is:');
|
||||||
|
console.log(response);
|
||||||
|
};
|
||||||
|
|
||||||
|
const getResponse2 = async () => {
|
||||||
|
const response = await smartcacheInstance
|
||||||
|
.cacheReturn(async () => {
|
||||||
|
console.log('function 2 ran');
|
||||||
|
return 'hello there!';
|
||||||
|
}, 1000)
|
||||||
|
.catch(err => {
|
||||||
|
console.log(err);
|
||||||
|
});
|
||||||
|
console.log('response is:');
|
||||||
|
console.log(response);
|
||||||
|
};
|
||||||
|
|
||||||
|
await getResponse();
|
||||||
|
await getResponse();
|
||||||
|
await getResponse2();
|
||||||
|
await getResponse2();
|
||||||
|
await smartdelay.delayFor(2000).then(async () => {
|
||||||
|
await getResponse();
|
||||||
|
await getResponse2();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.start({
|
||||||
|
throwOnError: true
|
||||||
|
});
|
||||||
|
@@ -20,9 +20,12 @@ export class CacheManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
stillValid(identifierArg: string): boolean {
|
stillValid(identifierArg: string): boolean {
|
||||||
if (this.cacheExists(identifierArg) && this._cacheMap[identifierArg].timer.startedAt.isYoungerThanMilliSeconds(
|
if (
|
||||||
this._cacheMap[identifierArg].timer.timeInMilliseconds
|
this.cacheExists(identifierArg) &&
|
||||||
)) {
|
this._cacheMap[identifierArg].timer.startedAt.isYoungerThanMilliSeconds(
|
||||||
|
this._cacheMap[identifierArg].timer.timeInMilliseconds
|
||||||
|
)
|
||||||
|
) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -37,21 +40,23 @@ export class CacheManager {
|
|||||||
};
|
};
|
||||||
this._cacheMap[identifierArg].timer.start();
|
this._cacheMap[identifierArg].timer.start();
|
||||||
this._cacheMap[identifierArg].timer.completed.then(() => {
|
this._cacheMap[identifierArg].timer.completed.then(() => {
|
||||||
this.deleteCache(identifierArg)
|
this.deleteCache(identifierArg);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* waits for the cache to be ready
|
* waits for the cache to be ready
|
||||||
*/
|
*/
|
||||||
async waitForCacheReady (identifierArg: string) {
|
async waitForCacheReady(identifierArg: string) {
|
||||||
await this._cacheMap[identifierArg].cachedDeferred.promise
|
await this._cacheMap[identifierArg].cachedDeferred.promise;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
setCache(identifierArg: string, cachedObjectArg: any, validForArg = 1000) {
|
setCache(identifierArg: string, cachedObjectArg: any, validForArg = 1000) {
|
||||||
if(!this.cacheExists(identifierArg)) {
|
if (!this.cacheExists(identifierArg)) {
|
||||||
console.log(new SmartError(`Cache for ${identifierArg} has not been announced or timed out!`));
|
console.log(
|
||||||
|
new SmartError(`Cache for ${identifierArg} has not been announced or timed out!`)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
this._cacheMap[identifierArg].cachedObject = cachedObjectArg;
|
this._cacheMap[identifierArg].cachedObject = cachedObjectArg;
|
||||||
this._cacheMap[identifierArg].cachedDeferred.resolve();
|
this._cacheMap[identifierArg].cachedDeferred.resolve();
|
||||||
|
@@ -5,15 +5,19 @@ export class SmartCache {
|
|||||||
private _cacheManager = new CacheManager();
|
private _cacheManager = new CacheManager();
|
||||||
|
|
||||||
async cacheReturn(asyncCachedFuncArg: () => Promise<any>, cacheDuration: number = 5000) {
|
async cacheReturn(asyncCachedFuncArg: () => Promise<any>, cacheDuration: number = 5000) {
|
||||||
let callStack: string = new plugins.smarterror.SmartError('').cleanFullStack;
|
const callStack: string = new plugins.smarterror.SmartError('Cache Creation Point').cleanFullStack.split('\n')[2];
|
||||||
let callHash = plugins.nodehash.sha256FromStringSync(callStack);
|
const callHash = plugins.smarthash.sha256FromStringSync(callStack);
|
||||||
|
|
||||||
console.log(callHash);
|
// 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;
|
return this._cacheManager.getCache(callHash).cachedObject;
|
||||||
} else {
|
} else {
|
||||||
this._cacheManager.announceCache(callHash, cacheDuration);
|
this._cacheManager.announceCache(callHash, cacheDuration);
|
||||||
let newCachedObject = await asyncCachedFuncArg()
|
const newCachedObject = await asyncCachedFuncArg();
|
||||||
this._cacheManager.setCache(callHash, newCachedObject, cacheDuration);
|
this._cacheManager.setCache(callHash, newCachedObject, cacheDuration);
|
||||||
return newCachedObject;
|
return newCachedObject;
|
||||||
}
|
}
|
||||||
|
@@ -2,6 +2,6 @@ import * as smartdelay from '@pushrocks/smartdelay';
|
|||||||
import * as smarterror from '@pushrocks/smarterror';
|
import * as smarterror from '@pushrocks/smarterror';
|
||||||
import * as smartpromise from '@pushrocks/smartpromise';
|
import * as smartpromise from '@pushrocks/smartpromise';
|
||||||
import * as smarttime from '@pushrocks/smarttime';
|
import * as smarttime from '@pushrocks/smarttime';
|
||||||
import * as nodehash from 'nodehash';
|
import * as smarthash from '@pushrocks/smarthash';
|
||||||
|
|
||||||
export { smarterror, smartdelay, smartpromise, smarttime, nodehash };
|
export { smarterror, smartdelay, smartpromise, smarttime, smarthash };
|
||||||
|
16
tslint.json
16
tslint.json
@@ -1,3 +1,17 @@
|
|||||||
{
|
{
|
||||||
"extends": "tslint-config-standard"
|
"extends": ["tslint:latest", "tslint-config-prettier"],
|
||||||
|
"rules": {
|
||||||
|
"semicolon": [true, "always"],
|
||||||
|
"no-console": false,
|
||||||
|
"ordered-imports": false,
|
||||||
|
"object-literal-sort-keys": false,
|
||||||
|
"member-ordering": {
|
||||||
|
"options":{
|
||||||
|
"order": [
|
||||||
|
"static-method"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"defaultSeverity": "warning"
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user