fix(core): update
This commit is contained in:
parent
d18f4b6928
commit
17b59fd222
4
.gitignore
vendored
4
.gitignore
vendored
@ -15,8 +15,6 @@ node_modules/
|
|||||||
|
|
||||||
# builds
|
# builds
|
||||||
dist/
|
dist/
|
||||||
dist_web/
|
dist_*/
|
||||||
dist_serve/
|
|
||||||
dist_ts_web/
|
|
||||||
|
|
||||||
# custom
|
# custom
|
@ -19,22 +19,35 @@ mirror:
|
|||||||
stage: security
|
stage: security
|
||||||
script:
|
script:
|
||||||
- npmci git mirror
|
- npmci git mirror
|
||||||
|
only:
|
||||||
|
- tags
|
||||||
tags:
|
tags:
|
||||||
- lossless
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
- notpriv
|
||||||
|
|
||||||
snyk:
|
auditProductionDependencies:
|
||||||
image: registry.gitlab.com/hosttoday/ht-docker-node:snyk
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
|
stage: security
|
||||||
|
script:
|
||||||
|
- 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
|
||||||
|
|
||||||
|
auditDevDependencies:
|
||||||
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
stage: security
|
stage: security
|
||||||
script:
|
script:
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci command npm install --ignore-scripts
|
- npmci command npm install --ignore-scripts
|
||||||
- npmci command snyk test
|
- npmci command npm config set registry https://registry.npmjs.org
|
||||||
|
- npmci command npm audit --audit-level=high --only=dev
|
||||||
tags:
|
tags:
|
||||||
- lossless
|
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
allow_failure: true
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# test stage
|
# test stage
|
||||||
@ -49,9 +62,7 @@ testStable:
|
|||||||
- npmci npm test
|
- npmci npm test
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- lossless
|
|
||||||
- docker
|
- docker
|
||||||
- priv
|
|
||||||
|
|
||||||
testBuild:
|
testBuild:
|
||||||
stage: test
|
stage: test
|
||||||
@ -62,9 +73,7 @@ testBuild:
|
|||||||
- npmci command npm run build
|
- npmci command npm run build
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- lossless
|
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
|
||||||
|
|
||||||
release:
|
release:
|
||||||
stage: release
|
stage: release
|
||||||
@ -84,6 +93,8 @@ release:
|
|||||||
codequality:
|
codequality:
|
||||||
stage: metadata
|
stage: metadata
|
||||||
allow_failure: true
|
allow_failure: true
|
||||||
|
only:
|
||||||
|
- tags
|
||||||
script:
|
script:
|
||||||
- npmci command npm install -g tslint typescript
|
- npmci command npm install -g tslint typescript
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
|
2
.vscode/settings.json
vendored
2
.vscode/settings.json
vendored
@ -15,7 +15,7 @@
|
|||||||
"properties": {
|
"properties": {
|
||||||
"projectType": {
|
"projectType": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"enum": ["website", "element", "service", "npm"]
|
"enum": ["website", "element", "service", "npm", "wcc"]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,11 +35,15 @@
|
|||||||
"ts/**/*",
|
"ts/**/*",
|
||||||
"ts_web/**/*",
|
"ts_web/**/*",
|
||||||
"dist/**/*",
|
"dist/**/*",
|
||||||
"dist_web/**/*",
|
"dist_*/**/*",
|
||||||
|
"dist_ts/**/*",
|
||||||
"dist_ts_web/**/*",
|
"dist_ts_web/**/*",
|
||||||
"assets/**/*",
|
"assets/**/*",
|
||||||
"cli.js",
|
"cli.js",
|
||||||
"npmextra.json",
|
"npmextra.json",
|
||||||
"readme.md"
|
"readme.md"
|
||||||
|
],
|
||||||
|
"browserslist": [
|
||||||
|
"last 1 chrome versions"
|
||||||
]
|
]
|
||||||
}
|
}
|
21
readme.md
21
readme.md
@ -8,13 +8,20 @@ a cache that uses memory/disk/s3 as backup
|
|||||||
* [docs (typedoc)](https://pushrocks.gitlab.io/levelcache/)
|
* [docs (typedoc)](https://pushrocks.gitlab.io/levelcache/)
|
||||||
|
|
||||||
## Status for master
|
## Status for master
|
||||||
[![pipeline status](https://gitlab.com/pushrocks/levelcache/badges/master/pipeline.svg)](https://gitlab.com/pushrocks/levelcache/commits/master)
|
|
||||||
[![coverage report](https://gitlab.com/pushrocks/levelcache/badges/master/coverage.svg)](https://gitlab.com/pushrocks/levelcache/commits/master)
|
Status Category | Status Badge
|
||||||
[![npm downloads per month](https://img.shields.io/npm/dm/@pushrocks/levelcache.svg)](https://www.npmjs.com/package/@pushrocks/levelcache)
|
-- | --
|
||||||
[![Known Vulnerabilities](https://snyk.io/test/npm/@pushrocks/levelcache/badge.svg)](https://snyk.io/test/npm/@pushrocks/levelcache)
|
GitLab Pipelines | [![pipeline status](https://gitlab.com/pushrocks/levelcache/badges/master/pipeline.svg)](https://lossless.cloud)
|
||||||
[![TypeScript](https://img.shields.io/badge/TypeScript->=%203.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/pushrocks/levelcache/badges/master/coverage.svg)](https://lossless.cloud)
|
||||||
[![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
npm | [![npm downloads per month](https://badgen.net/npm/dy/@pushrocks/levelcache)](https://lossless.cloud)
|
||||||
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-prettier-ff69b4.svg)](https://prettier.io/)
|
Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/pushrocks/levelcache)](https://lossless.cloud)
|
||||||
|
TypeScript Support | [![TypeScript](https://badgen.net/badge/TypeScript/>=%203.x/blue?icon=typescript)](https://lossless.cloud)
|
||||||
|
node Support | [![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||||
|
Code Style | [![Code Style](https://badgen.net/badge/style/prettier/purple)](https://lossless.cloud)
|
||||||
|
PackagePhobia (total standalone install weight) | [![PackagePhobia](https://badgen.net/packagephobia/install/@pushrocks/levelcache)](https://lossless.cloud)
|
||||||
|
PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@pushrocks/levelcache)](https://lossless.cloud)
|
||||||
|
BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@pushrocks/levelcache)](https://lossless.cloud)
|
||||||
|
Platform support | [![Supports Windows 10](https://badgen.net/badge/supports%20Windows%2010/yes/green?icon=windows)](https://lossless.cloud) [![Supports Mac OS X](https://badgen.net/badge/supports%20Mac%20OS%20X/yes/green?icon=apple)](https://lossless.cloud)
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
|
11
test/test.ts
11
test/test.ts
@ -6,17 +6,20 @@ let testLevelCache: levelcache.LevelCache;
|
|||||||
|
|
||||||
tap.test('should create a new levelcache instance', async () => {
|
tap.test('should create a new levelcache instance', async () => {
|
||||||
testLevelCache = new levelcache.LevelCache({
|
testLevelCache = new levelcache.LevelCache({
|
||||||
cacheId: 'myCache'
|
cacheId: 'myCache',
|
||||||
});
|
});
|
||||||
expect(testLevelCache).to.be.instanceOf(levelcache.LevelCache);
|
expect(testLevelCache).to.be.instanceOf(levelcache.LevelCache);
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should cache a value', async () => {
|
tap.test('should cache a value', async () => {
|
||||||
await testLevelCache.storeCacheEntryByKey('mykey', new CacheEntry({
|
await testLevelCache.storeCacheEntryByKey(
|
||||||
|
'mykey',
|
||||||
|
new CacheEntry({
|
||||||
contents: Buffer.from('heythere'),
|
contents: Buffer.from('heythere'),
|
||||||
ttl: 10000,
|
ttl: 10000,
|
||||||
typeInfo: 'string'
|
typeInfo: 'string',
|
||||||
}));
|
})
|
||||||
|
);
|
||||||
const result = await testLevelCache.retrieveCacheEntryByKey('mykey');
|
const result = await testLevelCache.retrieveCacheEntryByKey('mykey');
|
||||||
console.log(result);
|
console.log(result);
|
||||||
});
|
});
|
||||||
|
@ -1,3 +1,2 @@
|
|||||||
export * from './levelcache.classes.levelcache';
|
export * from './levelcache.classes.levelcache';
|
||||||
export * from './levelcache.classes.cacheentry';
|
export * from './levelcache.classes.cacheentry';
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { CacheEntry } from "./levelcache.classes.cacheentry";
|
import { CacheEntry } from './levelcache.classes.cacheentry';
|
||||||
|
|
||||||
export abstract class AbstractCache {
|
export abstract class AbstractCache {
|
||||||
public abstract ready: Promise<void>;
|
public abstract ready: Promise<void>;
|
||||||
|
@ -12,7 +12,7 @@ export class CacheDiskManager extends AbstractCache {
|
|||||||
private readyDeferred = plugins.smartpromise.defer<void>();
|
private readyDeferred = plugins.smartpromise.defer<void>();
|
||||||
|
|
||||||
public ready = this.readyDeferred.promise;
|
public ready = this.readyDeferred.promise;
|
||||||
public status: 'active' | 'inactive';
|
public status: 'active' | 'inactive';
|
||||||
public fsPath: string;
|
public fsPath: string;
|
||||||
public maxCacheSizeInMb: number;
|
public maxCacheSizeInMb: number;
|
||||||
|
|
||||||
@ -24,7 +24,10 @@ export class CacheDiskManager extends AbstractCache {
|
|||||||
|
|
||||||
public async init() {
|
public async init() {
|
||||||
if (this.levelCacheRef.options.diskStoragePath) {
|
if (this.levelCacheRef.options.diskStoragePath) {
|
||||||
this.fsPath = plugins.path.join(this.levelCacheRef.options.diskStoragePath, this.levelCacheRef.options.cacheId);
|
this.fsPath = plugins.path.join(
|
||||||
|
this.levelCacheRef.options.diskStoragePath,
|
||||||
|
this.levelCacheRef.options.cacheId
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
this.fsPath = plugins.path.join(paths.nogitDir, this.levelCacheRef.options.cacheId);
|
this.fsPath = plugins.path.join(paths.nogitDir, this.levelCacheRef.options.cacheId);
|
||||||
}
|
}
|
||||||
@ -35,12 +38,17 @@ export class CacheDiskManager extends AbstractCache {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async retrieveCacheEntryByKey(keyArg: string): Promise<CacheEntry> {
|
public async retrieveCacheEntryByKey(keyArg: string): Promise<CacheEntry> {
|
||||||
const fileString = await plugins.smartfile.fs.toStringSync(plugins.path.join(this.fsPath, encodeURIComponent(keyArg)));
|
const fileString = await plugins.smartfile.fs.toStringSync(
|
||||||
|
plugins.path.join(this.fsPath, encodeURIComponent(keyArg))
|
||||||
|
);
|
||||||
return CacheEntry.fromStorageJsonString(fileString);
|
return CacheEntry.fromStorageJsonString(fileString);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async storeCacheEntryByKey(keyArg: string, cacheEntryArg: CacheEntry) {
|
public async storeCacheEntryByKey(keyArg: string, cacheEntryArg: CacheEntry) {
|
||||||
await plugins.smartfile.memory.toFs(cacheEntryArg.foldToJson(), plugins.path.join(this.fsPath, encodeURIComponent(keyArg)));
|
await plugins.smartfile.memory.toFs(
|
||||||
|
cacheEntryArg.foldToJson(),
|
||||||
|
plugins.path.join(this.fsPath, encodeURIComponent(keyArg))
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async checkKeyPresence(keyArg): Promise<boolean> {
|
public async checkKeyPresence(keyArg): Promise<boolean> {
|
||||||
|
@ -41,5 +41,4 @@ export class CacheMemoryManager extends AbstractCache {
|
|||||||
public async clean() {
|
public async clean() {
|
||||||
this.fastMap.clean();
|
this.fastMap.clean();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,10 @@ export class CacheS3Manager extends AbstractCache {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async storeCacheEntryByKey(keyArg: string, cacheEntryArg: CacheEntry) {
|
public async storeCacheEntryByKey(keyArg: string, cacheEntryArg: CacheEntry) {
|
||||||
await this.s3CacheDir.fastStore(encodeURIComponent(keyArg), cacheEntryArg.toStorageJsonString());
|
await this.s3CacheDir.fastStore(
|
||||||
|
encodeURIComponent(keyArg),
|
||||||
|
cacheEntryArg.toStorageJsonString()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async checkKeyPresence(keyArg: string): Promise<boolean> {
|
public async checkKeyPresence(keyArg: string): Promise<boolean> {
|
||||||
|
@ -10,7 +10,9 @@ export interface ICacheEntryConstructorOptions {
|
|||||||
/**
|
/**
|
||||||
* a CacheEntry
|
* a CacheEntry
|
||||||
*/
|
*/
|
||||||
export class CacheEntry extends plugins.smartjson.Smartjson implements ICacheEntryConstructorOptions {
|
export class CacheEntry
|
||||||
|
extends plugins.smartjson.Smartjson
|
||||||
|
implements ICacheEntryConstructorOptions {
|
||||||
public static fromStorageJsonString(storageJsonString: string) {
|
public static fromStorageJsonString(storageJsonString: string) {
|
||||||
return new CacheEntry(plugins.smartjson.parse(storageJsonString));
|
return new CacheEntry(plugins.smartjson.parse(storageJsonString));
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,7 @@ export class CacheRouter {
|
|||||||
if (!returnCache && this.levelCacheRef.options.persistentCache) {
|
if (!returnCache && this.levelCacheRef.options.persistentCache) {
|
||||||
const checkCache = (cacheArg: AbstractCache) => {
|
const checkCache = (cacheArg: AbstractCache) => {
|
||||||
const resultPromise = cacheArg.checkKeyPresence(keyArg);
|
const resultPromise = cacheArg.checkKeyPresence(keyArg);
|
||||||
resultPromise.then(hasKeyArg => {
|
resultPromise.then((hasKeyArg) => {
|
||||||
if (hasKeyArg) {
|
if (hasKeyArg) {
|
||||||
done.resolve(cacheArg);
|
done.resolve(cacheArg);
|
||||||
}
|
}
|
||||||
@ -56,7 +56,7 @@ export class CacheRouter {
|
|||||||
Promise.all([
|
Promise.all([
|
||||||
checkCache(this.levelCacheRef.cacheMemoryManager),
|
checkCache(this.levelCacheRef.cacheMemoryManager),
|
||||||
checkCache(this.levelCacheRef.cacheDiskManager),
|
checkCache(this.levelCacheRef.cacheDiskManager),
|
||||||
checkCache(this.levelCacheRef.cacheMemoryManager)
|
checkCache(this.levelCacheRef.cacheMemoryManager),
|
||||||
]).then(() => {
|
]).then(() => {
|
||||||
done.resolve(returnCache);
|
done.resolve(returnCache);
|
||||||
});
|
});
|
||||||
|
@ -79,12 +79,11 @@ export class LevelCache extends AbstractCache {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public async checkKeyPresence(keyArg: string): Promise<boolean> {
|
public async checkKeyPresence(keyArg: string): Promise<boolean> {
|
||||||
return plugins.smartpromise.getFirstTrueOrFalse([
|
return plugins.smartpromise.getFirstTrueOrFalse([
|
||||||
this.cacheMemoryManager.checkKeyPresence(keyArg),
|
this.cacheMemoryManager.checkKeyPresence(keyArg),
|
||||||
this.cacheDiskManager.checkKeyPresence(keyArg),
|
this.cacheDiskManager.checkKeyPresence(keyArg),
|
||||||
this.cacheS3Manager.checkKeyPresence(keyArg)
|
this.cacheS3Manager.checkKeyPresence(keyArg),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user