Compare commits
17 Commits
Author | SHA1 | Date | |
---|---|---|---|
b5667be823 | |||
f147d48655 | |||
9eec43044d | |||
4df1274094 | |||
1edda548a1 | |||
c94b5e0009 | |||
fd5f5e357c | |||
57f50ef507 | |||
58bcf0cea2 | |||
bf2d3f661e | |||
eef3fd7c1f | |||
219944218c | |||
00364d261a | |||
04aa6b2fb5 | |||
e113ce5e8e | |||
3e2086fe34 | |||
f9e7204294 |
18
.gitignore
vendored
18
.gitignore
vendored
@@ -1,6 +1,22 @@
|
||||
.nogit/
|
||||
node_modules/
|
||||
|
||||
# artifacts
|
||||
coverage/
|
||||
public/
|
||||
pages/
|
||||
|
||||
# installs
|
||||
node_modules/
|
||||
|
||||
# caches
|
||||
.yarn/
|
||||
.cache/
|
||||
.rpt2_cache
|
||||
|
||||
# builds
|
||||
dist/
|
||||
dist_web/
|
||||
dist_serve/
|
||||
dist_ts_web/
|
||||
|
||||
# custom
|
@@ -1,5 +1,5 @@
|
||||
# gitzone standard
|
||||
image: hosttoday/ht-docker-node:npmci
|
||||
# gitzone ci_default
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
|
||||
cache:
|
||||
paths:
|
||||
@@ -26,6 +26,7 @@ mirror:
|
||||
snyk:
|
||||
stage: security
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci command npm install -g snyk
|
||||
- npmci command npm install --ignore-scripts
|
||||
- npmci command snyk test
|
||||
@@ -36,38 +37,29 @@ snyk:
|
||||
# ====================
|
||||
# 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:
|
||||
stage: test
|
||||
script:
|
||||
- npmci node install lts
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
testSTABLE:
|
||||
testStable:
|
||||
stage: test
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
- priv
|
||||
|
||||
testBuild:
|
||||
stage: test
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci command npm run build
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
release:
|
||||
@@ -86,19 +78,12 @@ release:
|
||||
# ====================
|
||||
codequality:
|
||||
stage: metadata
|
||||
image: docker:stable
|
||||
allow_failure: true
|
||||
services:
|
||||
- docker:stable-dind
|
||||
script:
|
||||
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
|
||||
- docker run
|
||||
--env SOURCE_CODE="$PWD"
|
||||
--volume "$PWD":/code
|
||||
--volume /var/run/docker.sock:/var/run/docker.sock
|
||||
"registry.gitlab.com/gitlab-org/security-products/codequality:$SP_VERSION" /code
|
||||
artifacts:
|
||||
paths: [codeclimate.json]
|
||||
- npmci command npm install -g tslint typescript
|
||||
- npmci npm prepare
|
||||
- npmci npm install
|
||||
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
||||
tags:
|
||||
- docker
|
||||
- priv
|
||||
@@ -114,11 +99,13 @@ trigger:
|
||||
- notpriv
|
||||
|
||||
pages:
|
||||
image: hosttoday/ht-docker-node:npmci
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci command npm install -g npmpage
|
||||
- npmci command npmpage
|
||||
- npmci node install lts
|
||||
- npmci command npm install -g @gitzone/tsdoc
|
||||
- npmci npm prepare
|
||||
- npmci npm install
|
||||
- npmci command tsdoc
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
@@ -129,13 +116,3 @@ pages:
|
||||
paths:
|
||||
- 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
|
||||
|
@@ -1,9 +1,16 @@
|
||||
{
|
||||
"npmci": {
|
||||
"npmGlobalTools": [
|
||||
"@gitzone/npmts",
|
||||
"ts-node"
|
||||
],
|
||||
"npmGlobalTools": [],
|
||||
"npmAccessLevel": "public"
|
||||
},
|
||||
"gitzone": {
|
||||
"module": {
|
||||
"githost": "gitlab.com",
|
||||
"gitscope": "pushrocks",
|
||||
"gitrepo": "smartcache",
|
||||
"shortDescription": "cache things in smart ways",
|
||||
"npmPackagename": "@pushrocks/smartcache",
|
||||
"license": "MIT"
|
||||
}
|
||||
}
|
||||
}
|
1701
package-lock.json
generated
1701
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
39
package.json
39
package.json
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "smartcache",
|
||||
"version": "1.0.3",
|
||||
"name": "@pushrocks/smartcache",
|
||||
"version": "1.0.12",
|
||||
"private": false,
|
||||
"description": "cache things in smart ways",
|
||||
"main": "dist/index.js",
|
||||
@@ -8,19 +8,34 @@
|
||||
"author": "Lossless GmbH",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"test": "(tsrun test/test.ts)",
|
||||
"build": "(npmts)"
|
||||
"test": "(tstest test/)",
|
||||
"build": "(tsbuild)"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@gitzone/tsrun": "^1.1.2",
|
||||
"@types/node": "^10.5.2",
|
||||
"tapbundle": "^2.0.2"
|
||||
"@gitzone/tsbuild": "^2.1.17",
|
||||
"@gitzone/tsrun": "^1.2.8",
|
||||
"@gitzone/tstest": "^1.0.28",
|
||||
"@pushrocks/tapbundle": "^3.0.13",
|
||||
"@types/node": "^12.11.5",
|
||||
"tslint": "^5.20.0",
|
||||
"tslint-config-prettier": "^1.18.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@pushrocks/smartdelay": "^2.0.1",
|
||||
"@pushrocks/smartdelay": "^2.0.3",
|
||||
"@pushrocks/smarterror": "^2.0.1",
|
||||
"@pushrocks/smartpromise": "^2.0.5",
|
||||
"@pushrocks/smarttime": "^2.0.1",
|
||||
"nodehash": "^1.0.4"
|
||||
}
|
||||
"@pushrocks/smarthash": "^2.0.6",
|
||||
"@pushrocks/smartpromise": "^3.0.6",
|
||||
"@pushrocks/smarttime": "^3.0.12"
|
||||
},
|
||||
"files": [
|
||||
"ts/**/*",
|
||||
"ts_web/**/*",
|
||||
"dist/**/*",
|
||||
"dist_web/**/*",
|
||||
"dist_ts_web/**/*",
|
||||
"assets/**/*",
|
||||
"cli.js",
|
||||
"npmextra.json",
|
||||
"readme.md"
|
||||
]
|
||||
}
|
||||
|
26
readme.md
Normal file
26
readme.md
Normal file
@@ -0,0 +1,26 @@
|
||||
# @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
|
||||
|
||||
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)
|
26
test/test.ts
26
test/test.ts
@@ -1,38 +1,38 @@
|
||||
import { expect, tap } from "tapbundle";
|
||||
import * as smartcache from "../ts/index";
|
||||
import * as smartdelay from "@pushrocks/smartdelay";
|
||||
import { expect, tap } from '@pushrocks/tapbundle';
|
||||
import * as smartcache from '../ts/index';
|
||||
import * as smartdelay from '@pushrocks/smartdelay';
|
||||
|
||||
let smartcacheInstance: smartcache.SmartCache;
|
||||
|
||||
tap.test("should create a valid instance of SmartCache", async () => {
|
||||
tap.test('should create a valid instance of SmartCache', async () => {
|
||||
smartcacheInstance = new smartcache.SmartCache();
|
||||
expect(smartcacheInstance).to.be.instanceof(smartcache.SmartCache);
|
||||
});
|
||||
|
||||
tap.test("try to get async responses", async () => {
|
||||
tap.test('try to get async responses', async () => {
|
||||
const getResponse = async () => {
|
||||
const response = await smartcacheInstance
|
||||
.cacheReturn(async () => {
|
||||
console.log("function ran");
|
||||
return "hello";
|
||||
console.log('function ran');
|
||||
return 'hello';
|
||||
}, 1000)
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
console.log("response is:");
|
||||
console.log('response is:');
|
||||
console.log(response);
|
||||
};
|
||||
|
||||
const getResponse2 = async () => {
|
||||
const response = await smartcacheInstance
|
||||
.cacheReturn(async () => {
|
||||
console.log("function 2 ran");
|
||||
return "hello";
|
||||
console.log('function 2 ran');
|
||||
return 'hello';
|
||||
}, 1000)
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
console.log("response is:");
|
||||
console.log('response is:');
|
||||
console.log(response);
|
||||
};
|
||||
|
||||
@@ -40,8 +40,8 @@ tap.test("try to get async responses", async () => {
|
||||
getResponse();
|
||||
getResponse2();
|
||||
getResponse2();
|
||||
smartdelay.delayFor(1000).then(() => {
|
||||
getResponse();
|
||||
await smartdelay.delayFor(1000).then(async () => {
|
||||
await getResponse();
|
||||
// getResponse2();
|
||||
});
|
||||
});
|
||||
|
@@ -6,9 +6,9 @@ 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);
|
||||
let callHash = plugins.smarthash.sha256FromStringSync(callStack);
|
||||
|
||||
console.log(callHash);
|
||||
// console.log(callHash);
|
||||
if (
|
||||
this._cacheManager.cacheExists(callHash) &&
|
||||
(await this._cacheManager.waitForCacheReady(callHash)) &&
|
||||
|
@@ -2,6 +2,6 @@ import * as smartdelay from '@pushrocks/smartdelay';
|
||||
import * as smarterror from '@pushrocks/smarterror';
|
||||
import * as smartpromise from '@pushrocks/smartpromise';
|
||||
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