Compare commits
34 Commits
Author | SHA1 | Date | |
---|---|---|---|
96080c5de0 | |||
a981c63f9b | |||
cd5e2f03f4 | |||
eb5c1f40ee | |||
ed1d66ee2a | |||
45122024fc | |||
fcaed1a3a0 | |||
0ce5eba798 | |||
9d6111a77f | |||
ac11045812 | |||
2266ee0c73 | |||
e4f0a60644 | |||
946e1cb7d3 | |||
6e5d17a793 | |||
3f7a3c2786 | |||
925921a9fe | |||
61ccf38d85 | |||
061a79b0fd | |||
2f4fb82918 | |||
266da3b476 | |||
074767b294 | |||
85abc4da3d | |||
716d805723 | |||
9feaa921bf | |||
6b57e8b1f3 | |||
f7b6df5ff7 | |||
6a4df84f4f | |||
17b59fd222 | |||
d18f4b6928 | |||
e53ebc74f8 | |||
be8227f451 | |||
d8f526ef2d | |||
92b858e248 | |||
26511fc10e |
66
.gitea/workflows/default_nottags.yaml
Normal file
66
.gitea/workflows/default_nottags.yaml
Normal 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
|
124
.gitea/workflows/default_tags.yaml
Normal file
124
.gitea/workflows/default_tags.yaml
Normal 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
|
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
|
126
.gitlab-ci.yml
126
.gitlab-ci.yml
@ -1,126 +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
|
|
||||||
tags:
|
|
||||||
- lossless
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
|
|
||||||
snyk:
|
|
||||||
image: registry.gitlab.com/hosttoday/ht-docker-node:snyk
|
|
||||||
stage: security
|
|
||||||
script:
|
|
||||||
- npmci npm prepare
|
|
||||||
- npmci command npm install --ignore-scripts
|
|
||||||
- npmci command snyk test
|
|
||||||
tags:
|
|
||||||
- lossless
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
|
|
||||||
# ====================
|
|
||||||
# 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:
|
|
||||||
- lossless
|
|
||||||
- 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:
|
|
||||||
- lossless
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
|
|
||||||
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
|
|
||||||
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
24
.vscode/launch.json
vendored
@ -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"
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
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"]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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"
|
||||||
}
|
}
|
||||||
|
1883
package-lock.json
generated
1883
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
51
package.json
51
package.json
@ -1,41 +1,54 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/levelcache",
|
"name": "@push.rocks/levelcache",
|
||||||
"version": "1.0.4",
|
"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/index.js",
|
"main": "dist_ts/index.js",
|
||||||
"typings": "dist/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/)",
|
"test": "(tstest test/ --web)",
|
||||||
"build": "(tsbuild)",
|
"build": "(tsbuild --web --allowimplicitany)",
|
||||||
"format": "(gitzone format)"
|
"buildDocs": "tsdoc",
|
||||||
|
"localPublish": "gitzone commit && pnpm run build && pnpm publish && pnpm publish --access public --registry=\"https://registry.npmjs.org\""
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.0.22",
|
"@gitzone/tsbuild": "^2.1.66",
|
||||||
"@gitzone/tstest": "^1.0.15",
|
"@gitzone/tsrun": "^1.2.44",
|
||||||
"@pushrocks/tapbundle": "^3.0.7",
|
"@gitzone/tstest": "^1.0.77",
|
||||||
"@types/node": "^13.7.0",
|
"@push.rocks/tapbundle": "^5.0.15",
|
||||||
"tslint": "^6.0.0",
|
"@types/node": "^20.11.17"
|
||||||
"tslint-config-prettier": "^1.15.0"
|
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/lik": "^3.0.16",
|
"@push.rocks/lik": "^6.0.12",
|
||||||
"@pushrocks/smartbucket": "^1.0.24",
|
"@push.rocks/smartbucket": "^2.0.4",
|
||||||
"@pushrocks/smartcache": "^1.0.13",
|
"@push.rocks/smartcache": "^1.0.13",
|
||||||
"@pushrocks/smartfile": "^7.0.6",
|
"@push.rocks/smartenv": "^5.0.12",
|
||||||
"@pushrocks/smartstring": "^3.0.18"
|
"@push.rocks/smartexit": "^1.0.21",
|
||||||
|
"@push.rocks/smartfile": "^11.0.4",
|
||||||
|
"@push.rocks/smartjson": "^5.0.10",
|
||||||
|
"@push.rocks/smartpath": "^5.0.11",
|
||||||
|
"@push.rocks/smartpromise": "^4.0.3",
|
||||||
|
"@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/**/*",
|
||||||
"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"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
6180
pnpm-lock.yaml
generated
Normal file
6180
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
38
readme.md
38
readme.md
@ -1,23 +1,32 @@
|
|||||||
# @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
|
||||||
[](https://gitlab.com/pushrocks/levelcache/commits/master)
|
|
||||||
[](https://gitlab.com/pushrocks/levelcache/commits/master)
|
Status Category | Status Badge
|
||||||
[](https://www.npmjs.com/package/@pushrocks/levelcache)
|
-- | --
|
||||||
[](https://snyk.io/test/npm/@pushrocks/levelcache)
|
GitLab Pipelines | [](https://lossless.cloud)
|
||||||
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
GitLab Pipline Test Coverage | [](https://lossless.cloud)
|
||||||
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
npm | [](https://lossless.cloud)
|
||||||
[](https://prettier.io/)
|
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)
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
|
@pushrocks/levelcache implements an efficient way to cache larger amounts of data ind a multilevel approach.
|
||||||
|
smaller and prioritized data is safed in memory.
|
||||||
|
|
||||||
Use TypeScript for best in class intellisense.
|
Use TypeScript for best in class intellisense.
|
||||||
|
|
||||||
## Contribution
|
## Contribution
|
||||||
@ -26,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)
|
||||||
|
|
||||||
[](https://maintainedby.lossless.com)
|
|
||||||
|
36
test/test.ts
36
test/test.ts
@ -1,15 +1,43 @@
|
|||||||
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.js';
|
||||||
|
|
||||||
let testLevelCache: levelcache.LevelCache;
|
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({
|
||||||
expect(testLevelCache).to.be.instanceOf(levelcache.LevelCache);
|
cacheId: 'myCache',
|
||||||
|
});
|
||||||
|
expect(testLevelCache).toBeInstanceOf(levelcache.LevelCache);
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should cache a value', async () => {
|
tap.test('should cache a value', async () => {
|
||||||
|
await testLevelCache.storeCacheEntryByKey(
|
||||||
|
'mykey',
|
||||||
|
new CacheEntry({
|
||||||
|
contents: Buffer.from('heythere'),
|
||||||
|
ttl: 10000,
|
||||||
|
typeInfo: 'string',
|
||||||
|
})
|
||||||
|
);
|
||||||
|
const result = await testLevelCache.retrieveCacheEntryByKey('mykey');
|
||||||
|
expect(result.contents.toString()).toEqual('heythere');
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('should respect ttl', async (tools) => {
|
||||||
|
await testLevelCache.storeCacheEntryByKey(
|
||||||
|
'mykey',
|
||||||
|
new CacheEntry({
|
||||||
|
contents: Buffer.from('heythere'),
|
||||||
|
ttl: 1000,
|
||||||
|
typeInfo: 'string',
|
||||||
|
})
|
||||||
|
);
|
||||||
|
const result = await testLevelCache.retrieveCacheEntryByKey('mykey');
|
||||||
|
expect(result.contents.toString()).toEqual('heythere');
|
||||||
|
await tools.delayFor(1100);
|
||||||
|
const result2 = await testLevelCache.retrieveCacheEntryByKey('mykey');
|
||||||
|
expect(result2).toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.start();
|
tap.start();
|
||||||
|
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: '@push.rocks/levelcache',
|
||||||
|
version: '3.0.8',
|
||||||
|
description: 'a cache that uses memory/disk/s3 as backup'
|
||||||
|
}
|
@ -1 +1,2 @@
|
|||||||
export * from './levelcache.classes.levelcache';
|
export * from './levelcache.classes.levelcache.js';
|
||||||
|
export * from './levelcache.classes.cacheentry.js';
|
||||||
|
38
ts/levelcache.abstract.classes.cache.ts
Normal file
38
ts/levelcache.abstract.classes.cache.ts
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
import { CacheEntry } from './levelcache.classes.cacheentry.js';
|
||||||
|
|
||||||
|
export abstract class AbstractCache {
|
||||||
|
public abstract ready: Promise<void>;
|
||||||
|
public abstract status: 'active' | 'inactive';
|
||||||
|
|
||||||
|
// Cache Entries
|
||||||
|
/**
|
||||||
|
* store a Blob
|
||||||
|
*/
|
||||||
|
public abstract storeCacheEntryByKey(keyArg: string, valueArg: CacheEntry): Promise<void>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* retrieve cache entry
|
||||||
|
*/
|
||||||
|
public abstract retrieveCacheEntryByKey(keyArg: string): Promise<CacheEntry>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* checks for the presence of a key
|
||||||
|
* @param keyArg
|
||||||
|
*/
|
||||||
|
public abstract checkKeyPresence(keyArg: string): Promise<boolean>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* delete a key
|
||||||
|
*/
|
||||||
|
public abstract deleteCacheEntryByKey(keyArg: string): Promise<void>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* clean the cache
|
||||||
|
*/
|
||||||
|
public abstract cleanOutdated(): Promise<void>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* cleans the complete cache
|
||||||
|
*/
|
||||||
|
public abstract cleanAll(): Promise<void>;
|
||||||
|
}
|
@ -1,8 +1,71 @@
|
|||||||
import * as plugins from './levelcache.plugins';
|
import * as plugins from './levelcache.plugins.js';
|
||||||
|
import * as paths from './levelcache.paths.js';
|
||||||
|
import { AbstractCache } from './levelcache.abstract.classes.cache.js';
|
||||||
|
import { type ILevelCacheConstructorOptions, LevelCache } from './levelcache.classes.levelcache.js';
|
||||||
|
import { CacheEntry } from './levelcache.classes.cacheentry.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
export class CacheDiskManager {
|
export class CacheDiskManager extends AbstractCache {
|
||||||
|
private levelCacheRef: LevelCache;
|
||||||
|
private readyDeferred = plugins.smartpromise.defer<void>();
|
||||||
|
|
||||||
}
|
public ready = this.readyDeferred.promise;
|
||||||
|
public status: 'active' | 'inactive';
|
||||||
|
public fsPath: string;
|
||||||
|
public maxCacheSizeInMb: number;
|
||||||
|
|
||||||
|
constructor(levelCacheRefArg: LevelCache) {
|
||||||
|
super();
|
||||||
|
this.levelCacheRef = levelCacheRefArg;
|
||||||
|
this.init();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async init() {
|
||||||
|
if (this.levelCacheRef.options.diskStoragePath) {
|
||||||
|
this.fsPath = plugins.path.join(
|
||||||
|
this.levelCacheRef.options.diskStoragePath,
|
||||||
|
this.levelCacheRef.options.cacheId
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
this.fsPath = plugins.path.join(paths.nogitDir, this.levelCacheRef.options.cacheId);
|
||||||
|
}
|
||||||
|
if (this.status === 'active') {
|
||||||
|
plugins.smartfile.fs.ensureDirSync(this.fsPath);
|
||||||
|
}
|
||||||
|
this.readyDeferred.resolve();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async retrieveCacheEntryByKey(keyArg: string): Promise<CacheEntry> {
|
||||||
|
const fileString = await plugins.smartfile.fs.toStringSync(
|
||||||
|
plugins.path.join(this.fsPath, encodeURIComponent(keyArg))
|
||||||
|
);
|
||||||
|
return CacheEntry.fromStorageJsonString(fileString);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async storeCacheEntryByKey(keyArg: string, cacheEntryArg: CacheEntry) {
|
||||||
|
await plugins.smartfile.memory.toFs(
|
||||||
|
cacheEntryArg.foldToJson(),
|
||||||
|
plugins.path.join(this.fsPath, encodeURIComponent(keyArg))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async checkKeyPresence(keyArg: string): Promise<boolean> {
|
||||||
|
return plugins.smartfile.fs.isFile(plugins.path.join(this.fsPath, encodeURIComponent(keyArg)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public async deleteCacheEntryByKey(keyArg: string) {
|
||||||
|
await plugins.smartfile.fs.remove(plugins.path.join(this.fsPath, encodeURIComponent(keyArg)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public async cleanOutdated() {}
|
||||||
|
|
||||||
|
public async cleanAll() {
|
||||||
|
if (this.status === 'active') {
|
||||||
|
if (plugins.smartfile.fs.isDirectory(this.fsPath)) {
|
||||||
|
await plugins.smartfile.fs.ensureEmptyDir(this.fsPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,5 +1,50 @@
|
|||||||
import * as plugins from './levelcache.plugins';
|
import * as plugins from './levelcache.plugins.js';
|
||||||
|
import { AbstractCache } from './levelcache.abstract.classes.cache.js';
|
||||||
|
import { CacheEntry } from './levelcache.classes.cacheentry.js';
|
||||||
|
import { type ILevelCacheConstructorOptions, LevelCache } from './levelcache.classes.levelcache.js';
|
||||||
|
|
||||||
export class CacheMemoryManager {
|
export class CacheMemoryManager extends AbstractCache {
|
||||||
|
private levelCacheRef: LevelCache;
|
||||||
}
|
private fastMap = new plugins.lik.FastMap<CacheEntry>();
|
||||||
|
private readyDeferred = plugins.smartpromise.defer<void>();
|
||||||
|
|
||||||
|
public ready = this.readyDeferred.promise;
|
||||||
|
public status: 'active' | 'inactive';
|
||||||
|
|
||||||
|
constructor(levelCacheRefArg: LevelCache) {
|
||||||
|
super();
|
||||||
|
this.levelCacheRef = levelCacheRefArg;
|
||||||
|
this.init();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async init() {
|
||||||
|
this.status = 'active';
|
||||||
|
this.readyDeferred.resolve();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async storeCacheEntryByKey(keyArg: string, cacheEntryArg: CacheEntry): Promise<void> {
|
||||||
|
this.fastMap.addToMap(keyArg, cacheEntryArg, { force: true });
|
||||||
|
}
|
||||||
|
|
||||||
|
public async retrieveCacheEntryByKey(keyArg: string): Promise<CacheEntry> {
|
||||||
|
return this.fastMap.getByKey(keyArg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async checkKeyPresence(keyArg: string): Promise<boolean> {
|
||||||
|
if (this.fastMap.getByKey(keyArg)) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async deleteCacheEntryByKey(keyArg: string) {
|
||||||
|
this.fastMap.removeFromMap(keyArg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async cleanOutdated() {}
|
||||||
|
|
||||||
|
public async cleanAll() {
|
||||||
|
this.fastMap.clean();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,8 +1,81 @@
|
|||||||
import * as plugins from './levelcache.plugins';
|
import * as plugins from './levelcache.plugins.js';
|
||||||
|
import { AbstractCache } from './levelcache.abstract.classes.cache.js';
|
||||||
|
import { LevelCache } from './levelcache.classes.levelcache.js';
|
||||||
|
import { CacheEntry } from './levelcache.classes.cacheentry.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
export class CacheS3Manager {
|
export class CacheS3Manager extends AbstractCache {
|
||||||
|
private levelCacheRef: LevelCache;
|
||||||
|
private smartbucket: plugins.smartbucket.SmartBucket;
|
||||||
|
private s3CacheBucket: plugins.smartbucket.Bucket;
|
||||||
|
private s3CacheDir: plugins.smartbucket.Directory;
|
||||||
|
private readyDeferred = plugins.smartpromise.defer<void>();
|
||||||
|
|
||||||
}
|
public ready = this.readyDeferred.promise;
|
||||||
|
public status: 'active' | 'inactive';
|
||||||
|
|
||||||
|
constructor(levelCacheRefArg: LevelCache) {
|
||||||
|
super();
|
||||||
|
this.levelCacheRef = levelCacheRefArg;
|
||||||
|
this.init();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async init() {
|
||||||
|
if (this.levelCacheRef.options.s3Config) {
|
||||||
|
this.smartbucket = new plugins.smartbucket.SmartBucket(this.levelCacheRef.options.s3Config);
|
||||||
|
this.s3CacheBucket = await this.smartbucket.getBucketByName('');
|
||||||
|
this.s3CacheDir = await (
|
||||||
|
await this.s3CacheBucket.getBaseDirectory()
|
||||||
|
).getSubDirectoryByName(this.levelCacheRef.options.cacheId);
|
||||||
|
if (this.levelCacheRef.options.maxS3StorageInMB) {
|
||||||
|
console.log(`cache level S3 activated with ${this.levelCacheRef.options.maxS3StorageInMB}`);
|
||||||
|
} else {
|
||||||
|
console.log(`s3 cache started without limit. Automatically applying timebox of 1 month`);
|
||||||
|
}
|
||||||
|
this.status = 'active';
|
||||||
|
} else {
|
||||||
|
this.status = 'inactive';
|
||||||
|
}
|
||||||
|
this.readyDeferred.resolve();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async retrieveCacheEntryByKey(keyArg: string): Promise<CacheEntry> {
|
||||||
|
const jsonFileString = (await this.s3CacheDir.fastGet(encodeURIComponent(keyArg))).toString();
|
||||||
|
const cacheEntry = CacheEntry.fromStorageJsonString(jsonFileString);
|
||||||
|
return cacheEntry;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async storeCacheEntryByKey(keyArg: string, cacheEntryArg: CacheEntry) {
|
||||||
|
await this.s3CacheDir.fastStore(
|
||||||
|
encodeURIComponent(keyArg),
|
||||||
|
cacheEntryArg.toStorageJsonString()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async checkKeyPresence(keyArg: string): Promise<boolean> {
|
||||||
|
const files = await this.s3CacheDir.listFiles();
|
||||||
|
for (const file of files) {
|
||||||
|
if (file.name === keyArg) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async deleteCacheEntryByKey(keyArg: string) {
|
||||||
|
if (this.status === 'active') {
|
||||||
|
await this.s3CacheDir.fastRemove(encodeURIComponent(keyArg));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* clean outdated
|
||||||
|
*/
|
||||||
|
public async cleanOutdated() {}
|
||||||
|
|
||||||
|
public async cleanAll() {
|
||||||
|
await this.s3CacheDir.deleteWithAllContents();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,5 +1,44 @@
|
|||||||
import * as plugins from './levelcache.plugins';
|
import * as plugins from './levelcache.plugins.js';
|
||||||
|
|
||||||
export class CacheEntry {
|
export interface ICacheEntryConstructorOptions {
|
||||||
|
key?: string;
|
||||||
}
|
ttl: number;
|
||||||
|
typeInfo?: string;
|
||||||
|
contents: Buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* a CacheEntry
|
||||||
|
*/
|
||||||
|
export class CacheEntry
|
||||||
|
extends plugins.smartjson.Smartjson
|
||||||
|
implements ICacheEntryConstructorOptions
|
||||||
|
{
|
||||||
|
public static fromStorageJsonString(storageJsonString: string) {
|
||||||
|
return new CacheEntry(plugins.smartjson.parse(storageJsonString));
|
||||||
|
}
|
||||||
|
|
||||||
|
@plugins.smartjson.foldDec()
|
||||||
|
public key: string;
|
||||||
|
|
||||||
|
@plugins.smartjson.foldDec()
|
||||||
|
public ttl: number;
|
||||||
|
|
||||||
|
@plugins.smartjson.foldDec()
|
||||||
|
public createdAt: number;
|
||||||
|
|
||||||
|
@plugins.smartjson.foldDec()
|
||||||
|
public typeInfo: string;
|
||||||
|
|
||||||
|
@plugins.smartjson.foldDec()
|
||||||
|
contents: Buffer;
|
||||||
|
|
||||||
|
public toStorageJsonString(): string {
|
||||||
|
return this.foldToJson();
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor(optionsArg: ICacheEntryConstructorOptions) {
|
||||||
|
super();
|
||||||
|
Object.assign(this, optionsArg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
75
ts/levelcache.classes.cacherouter.ts
Normal file
75
ts/levelcache.classes.cacherouter.ts
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
import * as plugins from './levelcache.plugins.js';
|
||||||
|
import { LevelCache } from './levelcache.classes.levelcache.js';
|
||||||
|
import { AbstractCache } from './levelcache.abstract.classes.cache.js';
|
||||||
|
import { CacheEntry } from './levelcache.classes.cacheentry.js';
|
||||||
|
|
||||||
|
export class CacheRouter {
|
||||||
|
public levelCacheRef: LevelCache;
|
||||||
|
public cacheKeyMap = new plugins.lik.FastMap<AbstractCache>();
|
||||||
|
|
||||||
|
constructor(levelCacheRef: LevelCache) {
|
||||||
|
this.levelCacheRef = levelCacheRef;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gets the relevant cache to perform a store action on
|
||||||
|
*/
|
||||||
|
async getCacheForStoreAction(keyArg: string, cacheEntry: CacheEntry): Promise<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) {
|
||||||
|
case cacheEntry.contents.byteLength <= maxMemoryBytes &&
|
||||||
|
this.levelCacheRef.cacheMemoryManager.status === 'active':
|
||||||
|
returnCache = this.levelCacheRef.cacheMemoryManager;
|
||||||
|
break;
|
||||||
|
case this.levelCacheRef.cacheDiskManager.status === 'active' &&
|
||||||
|
cacheEntry.contents.byteLength > maxMemoryBytes &&
|
||||||
|
cacheEntry.contents.byteLength <= maxDiskBytes &&
|
||||||
|
this.levelCacheRef.cacheDiskManager.status === 'active':
|
||||||
|
returnCache = this.levelCacheRef.cacheDiskManager;
|
||||||
|
break;
|
||||||
|
case cacheEntry.contents.byteLength > maxDiskBytes &&
|
||||||
|
cacheEntry.contents.byteLength < maxS3Bytes &&
|
||||||
|
this.levelCacheRef.cacheS3Manager.status === 'active':
|
||||||
|
returnCache = this.levelCacheRef.cacheS3Manager;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
returnCache = null;
|
||||||
|
}
|
||||||
|
this.cacheKeyMap.addToMap(keyArg, returnCache);
|
||||||
|
return returnCache;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gets the relevant cache to perform a retrieval action on
|
||||||
|
*/
|
||||||
|
async getCacheForRetrieveAction(keyArg: string): Promise<AbstractCache> {
|
||||||
|
const done = plugins.smartpromise.defer<AbstractCache>();
|
||||||
|
const returnCache = this.cacheKeyMap.getByKey(keyArg);
|
||||||
|
if (!returnCache && this.levelCacheRef.options.persistentCache) {
|
||||||
|
const checkCache = (cacheArg: AbstractCache) => {
|
||||||
|
const resultPromise = cacheArg.checkKeyPresence(keyArg);
|
||||||
|
resultPromise.then((hasKeyArg) => {
|
||||||
|
if (hasKeyArg) {
|
||||||
|
done.resolve(cacheArg);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return resultPromise;
|
||||||
|
};
|
||||||
|
Promise.all([
|
||||||
|
checkCache(this.levelCacheRef.cacheMemoryManager),
|
||||||
|
checkCache(this.levelCacheRef.cacheDiskManager),
|
||||||
|
checkCache(this.levelCacheRef.cacheMemoryManager),
|
||||||
|
]).then(() => {
|
||||||
|
done.resolve(returnCache);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
done.resolve(returnCache);
|
||||||
|
}
|
||||||
|
return done.promise;
|
||||||
|
}
|
||||||
|
}
|
@ -1,42 +1,121 @@
|
|||||||
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.js';
|
||||||
|
import { CacheRouter } from './levelcache.classes.cacherouter.js';
|
||||||
|
import { AbstractCache } from './levelcache.abstract.classes.cache.js';
|
||||||
|
|
||||||
|
export interface ILevelCacheConstructorOptions {
|
||||||
|
/**
|
||||||
|
* a unique id when having more than one cache
|
||||||
|
*/
|
||||||
|
cacheId: string;
|
||||||
|
maxMemoryStorageInMB?: number;
|
||||||
|
maxDiskStorageInMB?: number;
|
||||||
|
maxS3StorageInMB?: number;
|
||||||
|
diskStoragePath?: string;
|
||||||
|
s3Config?: plugins.tsclass.storage.IS3Descriptor;
|
||||||
|
s3BucketName?: string;
|
||||||
|
forceLevel?: 'memory' | 'disk' | 's3';
|
||||||
|
expirationInMs?: number;
|
||||||
|
immutableCache?: boolean;
|
||||||
|
persistentCache?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* a leveled cache for storing things for a short time
|
* a leveled cache for storing things for a short time
|
||||||
*/
|
*/
|
||||||
export class LevelCache {
|
export class LevelCache extends AbstractCache {
|
||||||
public cacheMap = new plugins.lik.Objectmap();
|
private readyDeferred = plugins.smartpromise.defer<void>();
|
||||||
public cacheDiskManager = new CacheDiskManager();
|
|
||||||
public cacheMemoryManager = new CacheMemoryManager();
|
|
||||||
public cacheS3Manager = new CacheS3Manager();
|
|
||||||
|
|
||||||
// Blobs
|
public ready = this.readyDeferred.promise;
|
||||||
/**
|
|
||||||
* store a Blob
|
|
||||||
*/
|
|
||||||
public async storeBlobByKey () {};
|
|
||||||
|
|
||||||
/**
|
public status: 'active' = 'active'; // artifact of AbstractCache
|
||||||
* retrieve a blob
|
|
||||||
*/
|
|
||||||
public async retrieveBlob () {};
|
|
||||||
|
|
||||||
|
public cacheRouter = new CacheRouter(this);
|
||||||
|
public cacheDiskManager: CacheDiskManager;
|
||||||
|
public cacheMemoryManager: CacheMemoryManager;
|
||||||
|
public cacheS3Manager: CacheS3Manager;
|
||||||
|
|
||||||
// Cache Entries
|
public options: ILevelCacheConstructorOptions;
|
||||||
/**
|
|
||||||
* store a Cache Entries
|
|
||||||
*/
|
|
||||||
public async storeCacheEntry() {};
|
|
||||||
|
|
||||||
|
constructor(optionsArg: ILevelCacheConstructorOptions) {
|
||||||
|
super();
|
||||||
|
this.options = {
|
||||||
|
maxMemoryStorageInMB: 0.5,
|
||||||
|
maxDiskStorageInMB: 10,
|
||||||
|
maxS3StorageInMB: 50,
|
||||||
|
...optionsArg,
|
||||||
|
};
|
||||||
|
this.init();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async init() {
|
||||||
|
this.cacheMemoryManager = new CacheMemoryManager(this);
|
||||||
|
this.cacheDiskManager = new CacheDiskManager(this);
|
||||||
|
this.cacheS3Manager = new CacheS3Manager(this);
|
||||||
|
await Promise.all([
|
||||||
|
this.cacheDiskManager.ready,
|
||||||
|
this.cacheMemoryManager.ready,
|
||||||
|
this.cacheS3Manager.ready,
|
||||||
|
]);
|
||||||
|
this.readyDeferred.resolve();
|
||||||
|
}
|
||||||
|
|
||||||
|
// store things
|
||||||
|
public async storeCacheEntryByKey(keyArg: string, cacheEntryArg: CacheEntry): Promise<void> {
|
||||||
|
cacheEntryArg.key = keyArg;
|
||||||
|
const targetCache = await this.cacheRouter.getCacheForStoreAction(keyArg, cacheEntryArg);
|
||||||
|
cacheEntryArg.createdAt = Date.now();
|
||||||
|
await targetCache.storeCacheEntryByKey(keyArg, cacheEntryArg);
|
||||||
|
}
|
||||||
|
|
||||||
|
// retrieve things
|
||||||
/**
|
/**
|
||||||
* retrieve cache entry
|
* retrieve cache entry
|
||||||
*/
|
*/
|
||||||
public async retrieveCacheEntry () {};
|
public async retrieveCacheEntryByKey(keyArg: string): Promise<CacheEntry> {
|
||||||
|
const targetCache = await this.cacheRouter.getCacheForRetrieveAction(keyArg);
|
||||||
|
if (targetCache) {
|
||||||
|
const cacheEntry = await targetCache.retrieveCacheEntryByKey(keyArg);
|
||||||
|
if (cacheEntry.createdAt + cacheEntry.ttl < Date.now()) {
|
||||||
|
await this.deleteCacheEntryByKey(keyArg).catch();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return cacheEntry;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async checkKeyPresence(keyArg: string): Promise<boolean> {
|
||||||
|
return plugins.smartpromise.getFirstTrueOrFalse([
|
||||||
|
this.cacheMemoryManager.checkKeyPresence(keyArg),
|
||||||
|
this.cacheDiskManager.checkKeyPresence(keyArg),
|
||||||
|
this.cacheS3Manager.checkKeyPresence(keyArg),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async deleteCacheEntryByKey(keyArg) {
|
||||||
|
await Promise.all([
|
||||||
|
this.cacheMemoryManager.deleteCacheEntryByKey(keyArg),
|
||||||
|
this.cacheDiskManager.deleteCacheEntryByKey(keyArg),
|
||||||
|
this.cacheS3Manager.deleteCacheEntryByKey(keyArg),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// cache maintenance
|
||||||
|
public async cleanOutdated() {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* cleans the cache
|
* cleans the complete cache
|
||||||
*/
|
*/
|
||||||
public clean() {};
|
public async cleanAll(): Promise<void> {
|
||||||
|
await Promise.all([
|
||||||
|
this.cacheDiskManager.cleanAll(),
|
||||||
|
this.cacheDiskManager.cleanAll(),
|
||||||
|
this.cacheS3Manager.cleanAll(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,7 @@
|
|||||||
|
import * as plugins from './levelcache.plugins.js';
|
||||||
|
|
||||||
|
export const packageDir = plugins.path.join(
|
||||||
|
plugins.smartpath.get.dirnameFromImportMetaUrl(import.meta.url),
|
||||||
|
'../'
|
||||||
|
);
|
||||||
|
export const nogitDir = plugins.path.join(packageDir, '.nogit/');
|
||||||
|
@ -1,21 +1,36 @@
|
|||||||
// node native scope
|
// node native scope
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
|
|
||||||
export {
|
export { path };
|
||||||
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 smartstring from '@pushrocks/smartstring';
|
import * as smartjson from '@push.rocks/smartjson';
|
||||||
|
import * as smartpath from '@push.rocks/smartpath';
|
||||||
|
import * as smartpromise from '@push.rocks/smartpromise';
|
||||||
|
import * as smartstring from '@push.rocks/smartstring';
|
||||||
|
import * as smartunique from '@push.rocks/smartunique';
|
||||||
|
import * as taskbuffer from '@push.rocks/taskbuffer';
|
||||||
|
|
||||||
export {
|
export {
|
||||||
lik,
|
lik,
|
||||||
smartbucket,
|
smartbucket,
|
||||||
smartcache,
|
smartcache,
|
||||||
smartfile,
|
smartfile,
|
||||||
smartstring
|
smartjson,
|
||||||
|
smartpath,
|
||||||
|
smartpromise,
|
||||||
|
smartstring,
|
||||||
|
smartunique,
|
||||||
|
taskbuffer,
|
||||||
|
};
|
||||||
|
|
||||||
|
// @tsclass scope
|
||||||
|
import * as tsclass from '@tsclass/tsclass';
|
||||||
|
|
||||||
|
export {
|
||||||
|
tsclass,
|
||||||
};
|
};
|
||||||
|
14
tsconfig.json
Normal file
14
tsconfig.json
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"experimentalDecorators": true,
|
||||||
|
"useDefineForClassFields": false,
|
||||||
|
"target": "ES2022",
|
||||||
|
"module": "NodeNext",
|
||||||
|
"moduleResolution": "NodeNext",
|
||||||
|
"esModuleInterop": true,
|
||||||
|
"verbatimModuleSyntax": true
|
||||||
|
},
|
||||||
|
"exclude": [
|
||||||
|
"dist_*/**/*.d.ts"
|
||||||
|
]
|
||||||
|
}
|
17
tslint.json
17
tslint.json
@ -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"
|
|
||||||
}
|
|
Reference in New Issue
Block a user