23 Commits

Author SHA1 Message Date
96080c5de0 3.0.8 2024-02-14 01:33:57 +01:00
a981c63f9b fix(core): update 2024-02-14 01:33:56 +01:00
cd5e2f03f4 3.0.7 2024-02-14 01:32:20 +01:00
eb5c1f40ee fix(core): update 2024-02-14 01:32:19 +01:00
ed1d66ee2a 3.0.6 2023-07-21 00:44:40 +02:00
45122024fc fix(core): update 2023-07-21 00:44:39 +02:00
fcaed1a3a0 3.0.5 2023-07-21 00:44:07 +02:00
0ce5eba798 fix(core): update 2023-07-21 00:44:06 +02:00
9d6111a77f 3.0.4 2023-07-20 22:54:08 +02:00
ac11045812 fix(core): update 2023-07-20 22:54:07 +02:00
2266ee0c73 switch to new org scheme 2023-07-11 00:00:42 +02:00
e4f0a60644 switch to new org scheme 2023-07-10 02:41:30 +02:00
946e1cb7d3 3.0.3 2023-01-09 13:01:09 +01:00
6e5d17a793 fix(core): update 2023-01-09 13:01:08 +01:00
3f7a3c2786 3.0.2 2022-06-09 19:23:56 +02:00
925921a9fe fix(core): update 2022-06-09 19:23:55 +02:00
61ccf38d85 3.0.1 2022-04-04 14:18:39 +02:00
061a79b0fd update 2022-04-04 14:18:36 +02:00
2f4fb82918 3.0.0 2022-04-02 17:40:38 +02:00
266da3b476 2.0.1 2022-03-22 23:15:08 +01:00
074767b294 fix(core): update 2022-03-22 23:15:08 +01:00
85abc4da3d 2.0.0 2022-03-22 22:45:13 +01:00
716d805723 BREAKING CHANGE(core): switch to esm 2022-03-22 22:45:12 +01:00
23 changed files with 6523 additions and 13471 deletions

View File

@ -0,0 +1,66 @@
name: Default (not tags)
on:
push:
tags-ignore:
- '**'
env:
IMAGE: registry.gitlab.com/hosttoday/ht-docker-node:npmci
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@gitea.lossless.digital/${{gitea.repository}}.git
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
NPMCI_URL_CLOUDLY: ${{secrets.NPMCI_URL_CLOUDLY}}
jobs:
security:
runs-on: ubuntu-latest
continue-on-error: true
container:
image: ${{ env.IMAGE }}
steps:
- uses: actions/checkout@v3
- name: Install pnpm and npmci
run: |
pnpm install -g pnpm
pnpm install -g @shipzone/npmci
- name: Run npm prepare
run: npmci npm prepare
- name: Audit production dependencies
run: |
npmci command npm config set registry https://registry.npmjs.org
npmci command pnpm audit --audit-level=high --prod
continue-on-error: true
- name: Audit development dependencies
run: |
npmci command npm config set registry https://registry.npmjs.org
npmci command pnpm audit --audit-level=high --dev
continue-on-error: true
test:
if: ${{ always() }}
needs: security
runs-on: ubuntu-latest
container:
image: ${{ env.IMAGE }}
steps:
- uses: actions/checkout@v3
- name: Test stable
run: |
npmci node install stable
npmci npm install
npmci npm test
- name: Test build
run: |
npmci node install stable
npmci npm install
npmci npm build

View File

@ -0,0 +1,124 @@
name: Default (tags)
on:
push:
tags:
- '*'
env:
IMAGE: registry.gitlab.com/hosttoday/ht-docker-node:npmci
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@gitea.lossless.digital/${{gitea.repository}}.git
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
NPMCI_URL_CLOUDLY: ${{secrets.NPMCI_URL_CLOUDLY}}
jobs:
security:
runs-on: ubuntu-latest
continue-on-error: true
container:
image: ${{ env.IMAGE }}
steps:
- uses: actions/checkout@v3
- name: Prepare
run: |
pnpm install -g pnpm
pnpm install -g @shipzone/npmci
npmci npm prepare
- name: Audit production dependencies
run: |
npmci command npm config set registry https://registry.npmjs.org
npmci command pnpm audit --audit-level=high --prod
continue-on-error: true
- name: Audit development dependencies
run: |
npmci command npm config set registry https://registry.npmjs.org
npmci command pnpm audit --audit-level=high --dev
continue-on-error: true
test:
if: ${{ always() }}
needs: security
runs-on: ubuntu-latest
container:
image: ${{ env.IMAGE }}
steps:
- uses: actions/checkout@v3
- name: Prepare
run: |
pnpm install -g pnpm
pnpm install -g @shipzone/npmci
npmci npm prepare
- name: Test stable
run: |
npmci node install stable
npmci npm install
npmci npm test
- name: Test build
run: |
npmci node install stable
npmci npm install
npmci npm build
release:
needs: test
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
container:
image: ${{ env.IMAGE }}
steps:
- uses: actions/checkout@v3
- name: Prepare
run: |
pnpm install -g pnpm
pnpm install -g @shipzone/npmci
npmci npm prepare
- name: Release
run: |
npmci node install stable
npmci npm publish
metadata:
needs: test
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
container:
image: ${{ env.IMAGE }}
continue-on-error: true
steps:
- uses: actions/checkout@v3
- name: Prepare
run: |
pnpm install -g pnpm
pnpm install -g @shipzone/npmci
npmci npm prepare
- name: Code quality
run: |
npmci command npm install -g typescript
npmci npm install
- name: Trigger
run: npmci trigger
- name: Build docs and upload artifacts
run: |
npmci node install stable
npmci npm install
pnpm install -g @gitzone/tsdoc
npmci command tsdoc
continue-on-error: true

View File

@ -1,137 +0,0 @@
# gitzone ci_default
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
cache:
paths:
- .npmci_cache/
key: '$CI_BUILD_STAGE'
stages:
- security
- test
- release
- metadata
# ====================
# security stage
# ====================
mirror:
stage: security
script:
- npmci git mirror
only:
- tags
tags:
- lossless
- docker
- notpriv
auditProductionDependencies:
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
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
# ====================
testStable:
stage: test
script:
- npmci npm prepare
- npmci node install stable
- npmci npm install
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
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
release:
stage: release
script:
- npmci node install stable
- npmci npm publish
only:
- tags
tags:
- lossless
- docker
- notpriv
# ====================
# metadata stage
# ====================
codequality:
stage: metadata
allow_failure: true
only:
- tags
script:
- npmci command npm install -g tslint typescript
- npmci npm prepare
- npmci npm install
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
tags:
- lossless
- docker
- priv
trigger:
stage: metadata
script:
- npmci trigger
only:
- tags
tags:
- lossless
- docker
- notpriv
pages:
stage: metadata
script:
- npmci node install lts
- npmci command npm install -g @gitzone/tsdoc
- npmci npm prepare
- npmci npm install
- npmci command tsdoc
tags:
- lossless
- docker
- notpriv
only:
- tags
artifacts:
expire_in: 1 week
paths:
- public
allow_failure: true

24
.vscode/launch.json vendored
View File

@ -2,28 +2,10 @@
"version": "0.2.0", "version": "0.2.0",
"configurations": [ "configurations": [
{ {
"name": "current file", "command": "npm test",
"type": "node", "name": "Run npm test",
"request": "launch", "request": "launch",
"args": [ "type": "node-terminal"
"${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"
} }
] ]
} }

View File

@ -3,10 +3,10 @@
"projectType": "npm", "projectType": "npm",
"module": { "module": {
"githost": "gitlab.com", "githost": "gitlab.com",
"gitscope": "pushrocks", "gitscope": "push.rocks",
"gitrepo": "levelcache", "gitrepo": "levelcache",
"shortDescription": "a cache that uses memory/disk/s3 as backup", "description": "a cache that uses memory/disk/s3 as backup",
"npmPackagename": "@pushrocks/levelcache", "npmPackagename": "@push.rocks/levelcache",
"license": "MIT", "license": "MIT",
"projectDomain": "push.rocks" "projectDomain": "push.rocks"
} }

13188
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,35 +1,40 @@
{ {
"name": "@pushrocks/levelcache", "name": "@push.rocks/levelcache",
"version": "1.0.10", "version": "3.0.8",
"private": false, "private": false,
"description": "a cache that uses memory/disk/s3 as backup", "description": "a cache that uses memory/disk/s3 as backup",
"main": "dist_ts/index.js", "main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts", "typings": "dist_ts/index.d.ts",
"type": "module",
"author": "Lossless GmbH", "author": "Lossless GmbH",
"license": "MIT", "license": "MIT",
"scripts": { "scripts": {
"test": "(tstest test/ --web)", "test": "(tstest test/ --web)",
"build": "(tsbuild --web)" "build": "(tsbuild --web --allowimplicitany)",
"buildDocs": "tsdoc",
"localPublish": "gitzone commit && pnpm run build && pnpm publish && pnpm publish --access public --registry=\"https://registry.npmjs.org\""
}, },
"devDependencies": { "devDependencies": {
"@gitzone/tsbuild": "^2.1.25", "@gitzone/tsbuild": "^2.1.66",
"@gitzone/tstest": "^1.0.52", "@gitzone/tsrun": "^1.2.44",
"@pushrocks/tapbundle": "^3.2.14", "@gitzone/tstest": "^1.0.77",
"@types/node": "^14.14.41", "@push.rocks/tapbundle": "^5.0.15",
"tslint": "^6.1.3", "@types/node": "^20.11.17"
"tslint-config-prettier": "^1.15.0"
}, },
"dependencies": { "dependencies": {
"@pushrocks/lik": "^4.0.20", "@push.rocks/lik": "^6.0.12",
"@pushrocks/smartbucket": "^1.0.39", "@push.rocks/smartbucket": "^2.0.4",
"@pushrocks/smartcache": "^1.0.13", "@push.rocks/smartcache": "^1.0.13",
"@pushrocks/smartexit": "^1.0.15", "@push.rocks/smartenv": "^5.0.12",
"@pushrocks/smartfile": "^8.0.9", "@push.rocks/smartexit": "^1.0.21",
"@pushrocks/smartjson": "^4.0.6", "@push.rocks/smartfile": "^11.0.4",
"@pushrocks/smartpromise": "^3.1.5", "@push.rocks/smartjson": "^5.0.10",
"@pushrocks/smartstring": "^3.0.24", "@push.rocks/smartpath": "^5.0.11",
"@pushrocks/smartunique": "^3.0.3", "@push.rocks/smartpromise": "^4.0.3",
"@pushrocks/taskbuffer": "^2.1.13" "@push.rocks/smartstring": "^4.0.13",
"@push.rocks/smartunique": "^3.0.6",
"@push.rocks/taskbuffer": "^3.1.7",
"@tsclass/tsclass": "^4.0.51"
}, },
"files": [ "files": [
"ts/**/*", "ts/**/*",

6180
pnpm-lock.yaml generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,27 +1,26 @@
# @pushrocks/levelcache # @push.rocks/levelcache
a cache that uses memory/disk/s3 as backup a cache that uses memory/disk/s3 as backup
## Availabililty and Links ## Availabililty and Links
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/levelcache) * [npmjs.org (npm package)](https://www.npmjs.com/package/@push.rocks/levelcache)
* [gitlab.com (source)](https://gitlab.com/pushrocks/levelcache) * [gitlab.com (source)](https://gitlab.com/push.rocks/levelcache)
* [github.com (source mirror)](https://github.com/pushrocks/levelcache) * [github.com (source mirror)](https://github.com/push.rocks/levelcache)
* [docs (typedoc)](https://pushrocks.gitlab.io/levelcache/) * [docs (typedoc)](https://push.rocks.gitlab.io/levelcache/)
## Status for master ## Status for master
Status Category | Status Badge Status Category | Status Badge
-- | -- -- | --
GitLab Pipelines | [![pipeline status](https://gitlab.com/pushrocks/levelcache/badges/master/pipeline.svg)](https://lossless.cloud) GitLab Pipelines | [![pipeline status](https://gitlab.com/push.rocks/levelcache/badges/master/pipeline.svg)](https://lossless.cloud)
GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/pushrocks/levelcache/badges/master/coverage.svg)](https://lossless.cloud) GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/push.rocks/levelcache/badges/master/coverage.svg)](https://lossless.cloud)
npm | [![npm downloads per month](https://badgen.net/npm/dy/@pushrocks/levelcache)](https://lossless.cloud) npm | [![npm downloads per month](https://badgen.net/npm/dy/@push.rocks/levelcache)](https://lossless.cloud)
Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/pushrocks/levelcache)](https://lossless.cloud) Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/push.rocks/levelcache)](https://lossless.cloud)
TypeScript Support | [![TypeScript](https://badgen.net/badge/TypeScript/>=%203.x/blue?icon=typescript)](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/) 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) 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 (total standalone install weight) | [![PackagePhobia](https://badgen.net/packagephobia/install/@push.rocks/levelcache)](https://lossless.cloud)
PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@pushrocks/levelcache)](https://lossless.cloud) PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@push.rocks/levelcache)](https://lossless.cloud)
BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@pushrocks/levelcache)](https://lossless.cloud) BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@push.rocks/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
@ -36,7 +35,6 @@ We are always happy for code contributions. If you are not the code contributing
For further information read the linked docs at the top of this readme. For further information read the linked docs at the top of this readme.
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh) ## Legal
> MIT licensed | **©** [Task Venture Capital GmbH](https://task.vc)
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy) | By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
[![repo-footer](https://lossless.gitlab.io/publicrelations/repofooter.svg)](https://maintainedby.lossless.com)

View File

@ -1,6 +1,6 @@
import { expect, tap } from '@pushrocks/tapbundle'; import { expect, tap } from '@push.rocks/tapbundle';
import * as levelcache from '../ts/index'; import * as levelcache from '../ts/index.js';
import { CacheEntry } from '../ts/index'; import { CacheEntry } from '../ts/index.js';
let testLevelCache: levelcache.LevelCache; let testLevelCache: levelcache.LevelCache;
@ -8,7 +8,7 @@ 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).toBeInstanceOf(levelcache.LevelCache);
}); });
tap.test('should cache a value', async () => { tap.test('should cache a value', async () => {
@ -21,7 +21,7 @@ tap.test('should cache a value', async () => {
}) })
); );
const result = await testLevelCache.retrieveCacheEntryByKey('mykey'); const result = await testLevelCache.retrieveCacheEntryByKey('mykey');
expect(result.contents.toString()).to.equal('heythere'); expect(result.contents.toString()).toEqual('heythere');
}); });
tap.test('should respect ttl', async (tools) => { tap.test('should respect ttl', async (tools) => {
@ -34,10 +34,10 @@ tap.test('should respect ttl', async (tools) => {
}) })
); );
const result = await testLevelCache.retrieveCacheEntryByKey('mykey'); const result = await testLevelCache.retrieveCacheEntryByKey('mykey');
expect(result.contents.toString()).to.equal('heythere'); expect(result.contents.toString()).toEqual('heythere');
await tools.delayFor(1100); await tools.delayFor(1100);
const result2 = await testLevelCache.retrieveCacheEntryByKey('mykey'); const result2 = await testLevelCache.retrieveCacheEntryByKey('mykey');
expect(result2).to.be.null; expect(result2).toBeNull();
}); });
tap.start(); tap.start();

8
ts/00_commitinfo_data.ts Normal file
View File

@ -0,0 +1,8 @@
/**
* autocreated commitinfo by @pushrocks/commitinfo
*/
export const commitinfo = {
name: '@push.rocks/levelcache',
version: '3.0.8',
description: 'a cache that uses memory/disk/s3 as backup'
}

View File

@ -1,2 +1,2 @@
export * from './levelcache.classes.levelcache'; export * from './levelcache.classes.levelcache.js';
export * from './levelcache.classes.cacheentry'; export * from './levelcache.classes.cacheentry.js';

View File

@ -1,4 +1,4 @@
import { CacheEntry } from './levelcache.classes.cacheentry'; import { CacheEntry } from './levelcache.classes.cacheentry.js';
export abstract class AbstractCache { export abstract class AbstractCache {
public abstract ready: Promise<void>; public abstract ready: Promise<void>;
@ -24,7 +24,7 @@ export abstract class AbstractCache {
/** /**
* delete a key * delete a key
*/ */
public abstract deleteCacheEntryByKey(keyArg: string): Promise<void>; public abstract deleteCacheEntryByKey(keyArg: string): Promise<void>;
/** /**
* clean the cache * clean the cache

View File

@ -1,8 +1,8 @@
import * as plugins from './levelcache.plugins'; import * as plugins from './levelcache.plugins.js';
import * as paths from './levelcache.paths'; import * as paths from './levelcache.paths.js';
import { AbstractCache } from './levelcache.abstract.classes.cache'; import { AbstractCache } from './levelcache.abstract.classes.cache.js';
import { ILevelCacheConstructorOptions, LevelCache } from './levelcache.classes.levelcache'; import { type ILevelCacheConstructorOptions, LevelCache } from './levelcache.classes.levelcache.js';
import { CacheEntry } from './levelcache.classes.cacheentry'; import { CacheEntry } from './levelcache.classes.cacheentry.js';
/** /**
* *
@ -59,7 +59,6 @@ export class CacheDiskManager extends AbstractCache {
await plugins.smartfile.fs.remove(plugins.path.join(this.fsPath, encodeURIComponent(keyArg))); await plugins.smartfile.fs.remove(plugins.path.join(this.fsPath, encodeURIComponent(keyArg)));
} }
public async cleanOutdated() {} public async cleanOutdated() {}
public async cleanAll() { public async cleanAll() {

View File

@ -1,7 +1,7 @@
import * as plugins from './levelcache.plugins'; import * as plugins from './levelcache.plugins.js';
import { AbstractCache } from './levelcache.abstract.classes.cache'; import { AbstractCache } from './levelcache.abstract.classes.cache.js';
import { CacheEntry } from './levelcache.classes.cacheentry'; import { CacheEntry } from './levelcache.classes.cacheentry.js';
import { ILevelCacheConstructorOptions, LevelCache } from './levelcache.classes.levelcache'; import { type ILevelCacheConstructorOptions, LevelCache } from './levelcache.classes.levelcache.js';
export class CacheMemoryManager extends AbstractCache { export class CacheMemoryManager extends AbstractCache {
private levelCacheRef: LevelCache; private levelCacheRef: LevelCache;

View File

@ -1,7 +1,7 @@
import * as plugins from './levelcache.plugins'; import * as plugins from './levelcache.plugins.js';
import { AbstractCache } from './levelcache.abstract.classes.cache'; import { AbstractCache } from './levelcache.abstract.classes.cache.js';
import { LevelCache } from './levelcache.classes.levelcache'; import { LevelCache } from './levelcache.classes.levelcache.js';
import { CacheEntry } from './levelcache.classes.cacheentry'; import { CacheEntry } from './levelcache.classes.cacheentry.js';
/** /**
* *
@ -26,9 +26,9 @@ export class CacheS3Manager extends AbstractCache {
if (this.levelCacheRef.options.s3Config) { if (this.levelCacheRef.options.s3Config) {
this.smartbucket = new plugins.smartbucket.SmartBucket(this.levelCacheRef.options.s3Config); this.smartbucket = new plugins.smartbucket.SmartBucket(this.levelCacheRef.options.s3Config);
this.s3CacheBucket = await this.smartbucket.getBucketByName(''); this.s3CacheBucket = await this.smartbucket.getBucketByName('');
this.s3CacheDir = await (await this.s3CacheBucket.getBaseDirectory()).getSubDirectoryByName( this.s3CacheDir = await (
this.levelCacheRef.options.cacheId await this.s3CacheBucket.getBaseDirectory()
); ).getSubDirectoryByName(this.levelCacheRef.options.cacheId);
if (this.levelCacheRef.options.maxS3StorageInMB) { if (this.levelCacheRef.options.maxS3StorageInMB) {
console.log(`cache level S3 activated with ${this.levelCacheRef.options.maxS3StorageInMB}`); console.log(`cache level S3 activated with ${this.levelCacheRef.options.maxS3StorageInMB}`);
} else { } else {
@ -65,7 +65,7 @@ export class CacheS3Manager extends AbstractCache {
} }
public async deleteCacheEntryByKey(keyArg: string) { public async deleteCacheEntryByKey(keyArg: string) {
if(this.status === 'active') { if (this.status === 'active') {
await this.s3CacheDir.fastRemove(encodeURIComponent(keyArg)); await this.s3CacheDir.fastRemove(encodeURIComponent(keyArg));
} }
} }

View File

@ -1,4 +1,4 @@
import * as plugins from './levelcache.plugins'; import * as plugins from './levelcache.plugins.js';
export interface ICacheEntryConstructorOptions { export interface ICacheEntryConstructorOptions {
key?: string; key?: string;
@ -12,7 +12,8 @@ export interface ICacheEntryConstructorOptions {
*/ */
export class CacheEntry export class CacheEntry
extends plugins.smartjson.Smartjson extends plugins.smartjson.Smartjson
implements ICacheEntryConstructorOptions { 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));
} }
@ -23,15 +24,15 @@ export class CacheEntry
@plugins.smartjson.foldDec() @plugins.smartjson.foldDec()
public ttl: number; public ttl: number;
@plugins.smartjson.foldDec()
public createdAt: number;
@plugins.smartjson.foldDec() @plugins.smartjson.foldDec()
public typeInfo: string; public typeInfo: string;
@plugins.smartjson.foldDec() @plugins.smartjson.foldDec()
contents: Buffer; contents: Buffer;
@plugins.smartjson.foldDec()
public createdAt: number;
public toStorageJsonString(): string { public toStorageJsonString(): string {
return this.foldToJson(); return this.foldToJson();
} }

View File

@ -1,7 +1,7 @@
import * as plugins from './levelcache.plugins'; import * as plugins from './levelcache.plugins.js';
import { LevelCache } from './levelcache.classes.levelcache'; import { LevelCache } from './levelcache.classes.levelcache.js';
import { AbstractCache } from './levelcache.abstract.classes.cache'; import { AbstractCache } from './levelcache.abstract.classes.cache.js';
import { CacheEntry } from './levelcache.classes.cacheentry'; import { CacheEntry } from './levelcache.classes.cacheentry.js';
export class CacheRouter { export class CacheRouter {
public levelCacheRef: LevelCache; public levelCacheRef: LevelCache;
@ -16,22 +16,29 @@ export class CacheRouter {
*/ */
async getCacheForStoreAction(keyArg: string, cacheEntry: CacheEntry): Promise<AbstractCache> { async getCacheForStoreAction(keyArg: string, cacheEntry: CacheEntry): Promise<AbstractCache> {
let returnCache: AbstractCache; let returnCache: AbstractCache;
const mbToBytesMultiplier = 1000 * 1000;
const maxMemoryBytes = this.levelCacheRef.options.maxMemoryStorageInMB * mbToBytesMultiplier;
const maxDiskBytes = this.levelCacheRef.options.maxDiskStorageInMB * mbToBytesMultiplier;
const maxS3Bytes = this.levelCacheRef.options.maxS3StorageInMB * mbToBytesMultiplier;
switch (true) { switch (true) {
case cacheEntry.contents.byteLength <= 500: case cacheEntry.contents.byteLength <= maxMemoryBytes &&
this.levelCacheRef.cacheMemoryManager.status === 'active':
returnCache = this.levelCacheRef.cacheMemoryManager; returnCache = this.levelCacheRef.cacheMemoryManager;
break; break;
case this.levelCacheRef.cacheDiskManager.status === 'active' && case this.levelCacheRef.cacheDiskManager.status === 'active' &&
cacheEntry.contents.byteLength >= 500 && cacheEntry.contents.byteLength > maxMemoryBytes &&
(cacheEntry.contents.byteLength < 10000 || cacheEntry.contents.byteLength <= maxDiskBytes &&
this.levelCacheRef.cacheS3Manager.status === 'inactive'): this.levelCacheRef.cacheDiskManager.status === 'active':
returnCache = this.levelCacheRef.cacheDiskManager; returnCache = this.levelCacheRef.cacheDiskManager;
break; break;
case cacheEntry.contents.byteLength >= 10000 && case cacheEntry.contents.byteLength > maxDiskBytes &&
cacheEntry.contents.byteLength < maxS3Bytes &&
this.levelCacheRef.cacheS3Manager.status === 'active': this.levelCacheRef.cacheS3Manager.status === 'active':
returnCache = this.levelCacheRef.cacheS3Manager; returnCache = this.levelCacheRef.cacheS3Manager;
break; break;
default: default:
returnCache = this.levelCacheRef.cacheMemoryManager; returnCache = null;
} }
this.cacheKeyMap.addToMap(keyArg, returnCache); this.cacheKeyMap.addToMap(keyArg, returnCache);
return returnCache; return returnCache;

View File

@ -1,10 +1,10 @@
import * as plugins from './levelcache.plugins'; import * as plugins from './levelcache.plugins.js';
import { CacheDiskManager } from './levelcache.classes.cache.diskmanager'; import { CacheDiskManager } from './levelcache.classes.cache.diskmanager.js';
import { CacheMemoryManager } from './levelcache.classes.cache.memorymanager'; import { CacheMemoryManager } from './levelcache.classes.cache.memorymanager.js';
import { CacheS3Manager } from './levelcache.classes.cache.s3manager'; import { CacheS3Manager } from './levelcache.classes.cache.s3manager.js';
import { CacheEntry } from './levelcache.classes.cacheentry'; import { CacheEntry } from './levelcache.classes.cacheentry.js';
import { CacheRouter } from './levelcache.classes.cacherouter'; import { CacheRouter } from './levelcache.classes.cacherouter.js';
import { AbstractCache } from './levelcache.abstract.classes.cache'; import { AbstractCache } from './levelcache.abstract.classes.cache.js';
export interface ILevelCacheConstructorOptions { export interface ILevelCacheConstructorOptions {
/** /**
@ -15,7 +15,7 @@ export interface ILevelCacheConstructorOptions {
maxDiskStorageInMB?: number; maxDiskStorageInMB?: number;
maxS3StorageInMB?: number; maxS3StorageInMB?: number;
diskStoragePath?: string; diskStoragePath?: string;
s3Config?: plugins.smartbucket.ISmartBucketConfig; s3Config?: plugins.tsclass.storage.IS3Descriptor;
s3BucketName?: string; s3BucketName?: string;
forceLevel?: 'memory' | 'disk' | 's3'; forceLevel?: 'memory' | 'disk' | 's3';
expirationInMs?: number; expirationInMs?: number;
@ -42,13 +42,18 @@ export class LevelCache extends AbstractCache {
constructor(optionsArg: ILevelCacheConstructorOptions) { constructor(optionsArg: ILevelCacheConstructorOptions) {
super(); super();
this.options = optionsArg; this.options = {
maxMemoryStorageInMB: 0.5,
maxDiskStorageInMB: 10,
maxS3StorageInMB: 50,
...optionsArg,
};
this.init(); this.init();
} }
public async init() { public async init() {
this.cacheDiskManager = new CacheDiskManager(this);
this.cacheMemoryManager = new CacheMemoryManager(this); this.cacheMemoryManager = new CacheMemoryManager(this);
this.cacheDiskManager = new CacheDiskManager(this);
this.cacheS3Manager = new CacheS3Manager(this); this.cacheS3Manager = new CacheS3Manager(this);
await Promise.all([ await Promise.all([
this.cacheDiskManager.ready, this.cacheDiskManager.ready,

View File

@ -1,4 +1,7 @@
import * as plugins from './levelcache.plugins'; import * as plugins from './levelcache.plugins.js';
export const packageDir = plugins.path.join(__dirname, '../'); export const packageDir = plugins.path.join(
plugins.smartpath.get.dirnameFromImportMetaUrl(import.meta.url),
'../'
);
export const nogitDir = plugins.path.join(packageDir, '.nogit/'); export const nogitDir = plugins.path.join(packageDir, '.nogit/');

View File

@ -3,16 +3,17 @@ import * as path from 'path';
export { path }; export { path };
// @pushrocks scope // @push.rocks scope
import * as lik from '@pushrocks/lik'; import * as lik from '@push.rocks/lik';
import * as smartbucket from '@pushrocks/smartbucket'; import * as smartbucket from '@push.rocks/smartbucket';
import * as smartcache from '@pushrocks/smartcache'; import * as smartcache from '@push.rocks/smartcache';
import * as smartfile from '@pushrocks/smartfile'; import * as smartfile from '@push.rocks/smartfile';
import * as smartjson from '@pushrocks/smartjson'; import * as smartjson from '@push.rocks/smartjson';
import * as smartpromise from '@pushrocks/smartpromise'; import * as smartpath from '@push.rocks/smartpath';
import * as smartstring from '@pushrocks/smartstring'; import * as smartpromise from '@push.rocks/smartpromise';
import * as smartunique from '@pushrocks/smartunique'; import * as smartstring from '@push.rocks/smartstring';
import * as taskbuffer from '@pushrocks/taskbuffer'; import * as smartunique from '@push.rocks/smartunique';
import * as taskbuffer from '@push.rocks/taskbuffer';
export { export {
lik, lik,
@ -20,8 +21,16 @@ export {
smartcache, smartcache,
smartfile, smartfile,
smartjson, smartjson,
smartpath,
smartpromise, smartpromise,
smartstring, smartstring,
smartunique, smartunique,
taskbuffer, taskbuffer,
}; };
// @tsclass scope
import * as tsclass from '@tsclass/tsclass';
export {
tsclass,
};

View File

@ -1,7 +1,14 @@
{ {
"compilerOptions": { "compilerOptions": {
"experimentalDecorators": true, "experimentalDecorators": true,
"target": "es2017", "useDefineForClassFields": false,
"module": "commonjs" "target": "ES2022",
} "module": "NodeNext",
"moduleResolution": "NodeNext",
"esModuleInterop": true,
"verbatimModuleSyntax": true
},
"exclude": [
"dist_*/**/*.d.ts"
]
} }

View File

@ -1,17 +0,0 @@
{
"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"
}