Compare commits
16 Commits
Author | SHA1 | Date | |
---|---|---|---|
677b07a176 | |||
0e11d0e760 | |||
1f80df6ec2 | |||
05997ef1cf | |||
dc5a93b3a2 | |||
51c1759961 | |||
b5667be823 | |||
f147d48655 | |||
9eec43044d | |||
4df1274094 | |||
1edda548a1 | |||
c94b5e0009 | |||
fd5f5e357c | |||
57f50ef507 | |||
58bcf0cea2 | |||
bf2d3f661e |
16
.gitignore
vendored
16
.gitignore
vendored
@@ -1,6 +1,20 @@
|
||||
.nogit/
|
||||
node_modules/
|
||||
|
||||
# artifacts
|
||||
coverage/
|
||||
public/
|
||||
pages/
|
||||
|
||||
# installs
|
||||
node_modules/
|
||||
|
||||
# caches
|
||||
.yarn/
|
||||
.cache/
|
||||
.rpt2_cache
|
||||
|
||||
# builds
|
||||
dist/
|
||||
dist_*/
|
||||
|
||||
# custom
|
150
.gitlab-ci.yml
150
.gitlab-ci.yml
@@ -1,16 +1,19 @@
|
||||
# gitzone standard
|
||||
image: hosttoday/ht-docker-node:npmci
|
||||
# gitzone ci_default
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
|
||||
cache:
|
||||
paths:
|
||||
- .npmci_cache/
|
||||
key: "$CI_BUILD_STAGE"
|
||||
- .npmci_cache/
|
||||
key: '$CI_BUILD_STAGE'
|
||||
|
||||
stages:
|
||||
- security
|
||||
- test
|
||||
- release
|
||||
- metadata
|
||||
- security
|
||||
- test
|
||||
- release
|
||||
- metadata
|
||||
|
||||
before_script:
|
||||
- npm install -g @shipzone/npmci
|
||||
|
||||
# ====================
|
||||
# security stage
|
||||
@@ -18,108 +21,113 @@ stages:
|
||||
mirror:
|
||||
stage: security
|
||||
script:
|
||||
- npmci git mirror
|
||||
- npmci git mirror
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
snyk:
|
||||
auditProductionDependencies:
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
stage: security
|
||||
script:
|
||||
- npmci command npm install -g snyk
|
||||
- npmci command npm install --ignore-scripts
|
||||
- npmci command snyk test
|
||||
- npmci npm prepare
|
||||
- npmci command npm install --production --ignore-scripts
|
||||
- npmci command npm config set registry https://registry.npmjs.org
|
||||
- npmci command npm audit --audit-level=high --only=prod --production
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
- docker
|
||||
allow_failure: true
|
||||
|
||||
auditDevDependencies:
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
stage: security
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci command npm install --ignore-scripts
|
||||
- npmci command npm config set registry https://registry.npmjs.org
|
||||
- npmci command npm audit --audit-level=high --only=dev
|
||||
tags:
|
||||
- docker
|
||||
allow_failure: true
|
||||
|
||||
# ====================
|
||||
# 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
|
||||
script:
|
||||
- npmci node install lts
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
- docker
|
||||
|
||||
testSTABLE:
|
||||
testBuild:
|
||||
stage: test
|
||||
script:
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci command npm run build
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
- docker
|
||||
|
||||
release:
|
||||
stage: release
|
||||
script:
|
||||
- npmci node install stable
|
||||
- npmci npm publish
|
||||
- npmci node install stable
|
||||
- npmci npm publish
|
||||
only:
|
||||
- tags
|
||||
- tags
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
# ====================
|
||||
# metadata stage
|
||||
# ====================
|
||||
codequality:
|
||||
stage: metadata
|
||||
image: docker:stable
|
||||
allow_failure: true
|
||||
services:
|
||||
- docker:stable-dind
|
||||
only:
|
||||
- tags
|
||||
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 typescript
|
||||
- npmci npm prepare
|
||||
- npmci npm install
|
||||
tags:
|
||||
- docker
|
||||
- priv
|
||||
- lossless
|
||||
- docker
|
||||
- priv
|
||||
|
||||
trigger:
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci trigger
|
||||
- npmci trigger
|
||||
only:
|
||||
- tags
|
||||
- tags
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
pages:
|
||||
image: hosttoday/ht-docker-node:npmci
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci command npm install -g npmpage
|
||||
- npmci command npmpage
|
||||
- npmci node install stable
|
||||
- npmci npm prepare
|
||||
- npmci npm install
|
||||
- npmci command npm run buildDocs
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
only:
|
||||
@@ -127,15 +135,5 @@ pages:
|
||||
artifacts:
|
||||
expire_in: 1 week
|
||||
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
|
||||
- public
|
||||
allow_failure: true
|
||||
|
11
.vscode/launch.json
vendored
Normal file
11
.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"command": "npm test",
|
||||
"name": "Run npm test",
|
||||
"request": "launch",
|
||||
"type": "node-terminal"
|
||||
}
|
||||
]
|
||||
}
|
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", "wcc"]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
@@ -2,5 +2,16 @@
|
||||
"npmci": {
|
||||
"npmGlobalTools": [],
|
||||
"npmAccessLevel": "public"
|
||||
},
|
||||
"gitzone": {
|
||||
"projectType": "npm",
|
||||
"module": {
|
||||
"githost": "gitlab.com",
|
||||
"gitscope": "pushrocks",
|
||||
"gitrepo": "smartcache",
|
||||
"description": "cache things in smart ways",
|
||||
"npmPackagename": "@pushrocks/smartcache",
|
||||
"license": "MIT"
|
||||
}
|
||||
}
|
||||
}
|
11455
package-lock.json
generated
11455
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
47
package.json
47
package.json
@@ -1,28 +1,47 @@
|
||||
{
|
||||
"name": "@pushrocks/smartcache",
|
||||
"version": "1.0.7",
|
||||
"version": "1.0.15",
|
||||
"private": false,
|
||||
"description": "cache things in smart ways",
|
||||
"main": "dist/index.js",
|
||||
"typings": "dist/index.d.ts",
|
||||
"main": "dist_ts/index.js",
|
||||
"typings": "dist_ts/index.d.ts",
|
||||
"author": "Lossless GmbH",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"test": "(tstest test/)",
|
||||
"build": "(tsbuild)"
|
||||
"build": "(tsbuild)",
|
||||
"buildDocs": "tsdoc"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@gitzone/tsbuild": "^2.0.22",
|
||||
"@gitzone/tsrun": "^1.1.12",
|
||||
"@gitzone/tstest": "^1.0.15",
|
||||
"@pushrocks/tapbundle": "^3.0.5",
|
||||
"@types/node": "^10.7.1"
|
||||
"@gitzone/tsbuild": "^2.1.63",
|
||||
"@gitzone/tsrun": "^1.2.37",
|
||||
"@gitzone/tstest": "^1.0.71",
|
||||
"@pushrocks/tapbundle": "^5.0.3",
|
||||
"@types/node": "^18.0.0",
|
||||
"tslint": "^6.1.3",
|
||||
"tslint-config-prettier": "^1.18.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@pushrocks/smartdelay": "^2.0.2",
|
||||
"@pushrocks/smartdelay": "^2.0.13",
|
||||
"@pushrocks/smarterror": "^2.0.1",
|
||||
"@pushrocks/smartpromise": "^2.0.5",
|
||||
"@pushrocks/smarttime": "^2.0.2",
|
||||
"nodehash": "^1.0.4"
|
||||
}
|
||||
"@pushrocks/smarthash": "^3.0.1",
|
||||
"@pushrocks/smartpromise": "^3.1.7",
|
||||
"@pushrocks/smarttime": "^3.0.45"
|
||||
},
|
||||
"files": [
|
||||
"ts/**/*",
|
||||
"ts_web/**/*",
|
||||
"dist/**/*",
|
||||
"dist_*/**/*",
|
||||
"dist_ts/**/*",
|
||||
"dist_ts_web/**/*",
|
||||
"assets/**/*",
|
||||
"cli.js",
|
||||
"npmextra.json",
|
||||
"readme.md"
|
||||
],
|
||||
"browserslist": [
|
||||
"last 1 chrome versions"
|
||||
],
|
||||
"type": "module"
|
||||
}
|
||||
|
41
readme.md
Normal file
41
readme.md
Normal file
@@ -0,0 +1,41 @@
|
||||
# @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
|
||||
|
||||
Status Category | Status Badge
|
||||
-- | --
|
||||
GitLab Pipelines | [](https://lossless.cloud)
|
||||
GitLab Pipline Test Coverage | [](https://lossless.cloud)
|
||||
npm | [](https://lossless.cloud)
|
||||
Snyk | [](https://lossless.cloud)
|
||||
TypeScript Support | [](https://lossless.cloud)
|
||||
node Support | [](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||
Code Style | [](https://lossless.cloud)
|
||||
PackagePhobia (total standalone install weight) | [](https://lossless.cloud)
|
||||
PackagePhobia (package size on registry) | [](https://lossless.cloud)
|
||||
BundlePhobia (total size when bundled) | [](https://lossless.cloud)
|
||||
Platform support | [](https://lossless.cloud) [](https://lossless.cloud)
|
||||
|
||||
## 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). :)
|
||||
|
||||
## 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)
|
49
test/test.ts
49
test/test.ts
@@ -1,51 +1,54 @@
|
||||
import { expect, tap } from "@pushrocks/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.js';
|
||||
|
||||
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);
|
||||
expect(smartcacheInstance).toBeInstanceOf(smartcache.SmartCache);
|
||||
});
|
||||
|
||||
tap.test("try to get async responses", async () => {
|
||||
tap.test('try to get async responses', async (toolsArg) => {
|
||||
let response1Counter = 0;
|
||||
const getResponse = async () => {
|
||||
const response = await smartcacheInstance
|
||||
.cacheReturn(async () => {
|
||||
console.log("function ran");
|
||||
return "hello";
|
||||
console.log('function 1 ran');
|
||||
response1Counter++;
|
||||
return 'hello';
|
||||
}, 1000)
|
||||
.catch(err => {
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
});
|
||||
console.log("response is:");
|
||||
console.log('response is:');
|
||||
console.log(response);
|
||||
};
|
||||
|
||||
let response2Counter = 0;
|
||||
const getResponse2 = async () => {
|
||||
const response = await smartcacheInstance
|
||||
.cacheReturn(async () => {
|
||||
console.log("function 2 ran");
|
||||
return "hello";
|
||||
console.log('function 2 ran');
|
||||
response2Counter++;
|
||||
return 'hello there!';
|
||||
}, 1000)
|
||||
.catch(err => {
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
});
|
||||
console.log("response is:");
|
||||
console.log('response is:');
|
||||
console.log(response);
|
||||
};
|
||||
|
||||
getResponse();
|
||||
getResponse();
|
||||
getResponse2();
|
||||
getResponse2();
|
||||
smartdelay.delayFor(1000).then(() => {
|
||||
getResponse();
|
||||
// getResponse2();
|
||||
});
|
||||
await getResponse();
|
||||
await getResponse();
|
||||
await getResponse2();
|
||||
await getResponse2();
|
||||
await toolsArg.delayFor(500);
|
||||
await getResponse();
|
||||
await toolsArg.delayFor(2000);
|
||||
await getResponse2();
|
||||
});
|
||||
|
||||
tap.start({
|
||||
throwOnError: true
|
||||
throwOnError: true,
|
||||
});
|
||||
|
8
ts/00_commitinfo_data.ts
Normal file
8
ts/00_commitinfo_data.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* autocreated commitinfo by @pushrocks/commitinfo
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@pushrocks/smartcache',
|
||||
version: '1.0.15',
|
||||
description: 'cache things in smart ways'
|
||||
}
|
@@ -1 +1 @@
|
||||
export * from './smartcache.classes.smartcache';
|
||||
export * from './smartcache.classes.smartcache.js';
|
||||
|
@@ -1,4 +1,4 @@
|
||||
import * as plugins from './smartcache.plugins';
|
||||
import * as plugins from './smartcache.plugins.js';
|
||||
import { SmartError } from '@pushrocks/smarterror';
|
||||
|
||||
export interface ICacheMap {
|
||||
@@ -12,7 +12,7 @@ export interface ICacheMap {
|
||||
export class CacheManager {
|
||||
private _cacheMap: ICacheMap = {};
|
||||
|
||||
cacheExists(identifierArg): boolean {
|
||||
cacheExists(identifierArg: string): boolean {
|
||||
if (this._cacheMap[identifierArg]) {
|
||||
return true;
|
||||
}
|
||||
@@ -36,7 +36,7 @@ export class CacheManager {
|
||||
this._cacheMap[identifierArg] = {
|
||||
timer: new plugins.smarttime.Timer(validForArg),
|
||||
cachedDeferred: new plugins.smartpromise.Deferred(),
|
||||
cachedObject: null
|
||||
cachedObject: null,
|
||||
};
|
||||
this._cacheMap[identifierArg].timer.start();
|
||||
this._cacheMap[identifierArg].timer.completed.then(() => {
|
||||
|
@@ -1,14 +1,16 @@
|
||||
import * as plugins from './smartcache.plugins';
|
||||
import { CacheManager } from './smartcache.classes.cachemanager';
|
||||
import * as plugins from './smartcache.plugins.js';
|
||||
import { CacheManager } from './smartcache.classes.cachemanager.js';
|
||||
|
||||
export class SmartCache {
|
||||
private _cacheManager = new CacheManager();
|
||||
|
||||
async cacheReturn(asyncCachedFuncArg: () => Promise<any>, cacheDuration: number = 5000) {
|
||||
let callStack: string = new plugins.smarterror.SmartError('').cleanFullStack;
|
||||
let callHash = plugins.nodehash.sha256FromStringSync(callStack);
|
||||
const callStack: string = new plugins.smarterror.SmartError(
|
||||
'Cache Creation Point'
|
||||
).cleanFullStack.split('\n')[2];
|
||||
const callHash = plugins.smarthash.sha256FromStringSync(callStack);
|
||||
|
||||
console.log(callHash);
|
||||
// console.log(callHash);
|
||||
if (
|
||||
this._cacheManager.cacheExists(callHash) &&
|
||||
(await this._cacheManager.waitForCacheReady(callHash)) &&
|
||||
@@ -17,7 +19,7 @@ export class SmartCache {
|
||||
return this._cacheManager.getCache(callHash).cachedObject;
|
||||
} else {
|
||||
this._cacheManager.announceCache(callHash, cacheDuration);
|
||||
let newCachedObject = await asyncCachedFuncArg();
|
||||
const newCachedObject = await asyncCachedFuncArg();
|
||||
this._cacheManager.setCache(callHash, newCachedObject, cacheDuration);
|
||||
return newCachedObject;
|
||||
}
|
||||
|
@@ -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 };
|
||||
|
9
tsconfig.json
Normal file
9
tsconfig.json
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"experimentalDecorators": true,
|
||||
"useDefineForClassFields": false,
|
||||
"target": "ES2022",
|
||||
"module": "ES2022",
|
||||
"moduleResolution": "nodenext"
|
||||
}
|
||||
}
|
@@ -1,3 +0,0 @@
|
||||
{
|
||||
"extends": "tslint-config-standard"
|
||||
}
|
Reference in New Issue
Block a user