@steedos/cachers 2.2.51-beta.1 → 2.2.51-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/lib/index.d.ts +0 -3
- package/lib/memory-lru.d.ts +0 -11
- package/lib/memory.d.ts +0 -10
- package/src/index.ts +0 -34
- package/src/memory-lru.ts +0 -54
- package/src/memory.ts +0 -39
- package/tsconfig.json +0 -36
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@steedos/cachers",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "2.2.51-beta.
|
|
4
|
+
"version": "2.2.51-beta.2",
|
|
5
5
|
"description": "",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"scripts": {
|
|
@@ -19,5 +19,5 @@
|
|
|
19
19
|
"publishConfig": {
|
|
20
20
|
"access": "public"
|
|
21
21
|
},
|
|
22
|
-
"gitHead": "
|
|
22
|
+
"gitHead": "c324c40fa8facd3bf73a51e8c417293a9349f9fb"
|
|
23
23
|
}
|
package/lib/index.d.ts
DELETED
package/lib/memory-lru.d.ts
DELETED
package/lib/memory.d.ts
DELETED
package/src/index.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* @Author: baozhoutao@steedos.com
|
|
3
|
-
* @Date: 2022-06-09 15:03:56
|
|
4
|
-
* @LastEditors: baozhoutao@steedos.com
|
|
5
|
-
* @LastEditTime: 2022-06-10 11:16:07
|
|
6
|
-
* @Description:
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const CACHER_MAP = {};
|
|
11
|
-
|
|
12
|
-
import { MemoryCacher } from './memory';
|
|
13
|
-
import { MemoryLRUCacher } from './memory-lru'
|
|
14
|
-
|
|
15
|
-
export const getCacher = function (name: string, options?: any) {
|
|
16
|
-
if(!CACHER_MAP[name]){
|
|
17
|
-
if(name.startsWith('lru.')){
|
|
18
|
-
CACHER_MAP[name] = new MemoryLRUCacher(options);
|
|
19
|
-
}else{
|
|
20
|
-
CACHER_MAP[name] = new MemoryCacher();
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
return CACHER_MAP[name];
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export const clearCacher = function (name: string | number) {
|
|
27
|
-
if(CACHER_MAP[name]){
|
|
28
|
-
CACHER_MAP[name].clear();
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export const getCacherNames = function(){
|
|
33
|
-
return Object.keys(CACHER_MAP);
|
|
34
|
-
}
|
package/src/memory-lru.ts
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* @Author: baozhoutao@steedos.com
|
|
3
|
-
* @Date: 2022-06-10 09:33:03
|
|
4
|
-
* @LastEditors: baozhoutao@steedos.com
|
|
5
|
-
* @LastEditTime: 2022-06-14 19:01:42
|
|
6
|
-
* @Description:
|
|
7
|
-
*/
|
|
8
|
-
import { defaultsDeep } from 'lodash';
|
|
9
|
-
|
|
10
|
-
const LRU = require('lru-cache');
|
|
11
|
-
|
|
12
|
-
const defaultOptions = {
|
|
13
|
-
max: 5000,
|
|
14
|
-
ttl: null,
|
|
15
|
-
keygen: null,
|
|
16
|
-
maxParamsLength: null
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export class MemoryLRUCacher {
|
|
20
|
-
private cache: any;
|
|
21
|
-
opts: any;
|
|
22
|
-
constructor(opts){
|
|
23
|
-
this.opts = defaultsDeep(opts, defaultOptions);
|
|
24
|
-
this.cache = new LRU({
|
|
25
|
-
max: this.opts.max,
|
|
26
|
-
maxAge: this.opts.ttl ? this.opts.ttl * 1000 : null,
|
|
27
|
-
updateAgeOnGet: !!this.opts.ttl
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
get(key: string){
|
|
32
|
-
return this.cache.get(key);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
set(key: string, data: any, opt?: any){
|
|
36
|
-
return this.cache.set(key, data, opt);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
delete(key: string){
|
|
40
|
-
return this.cache.delete(key);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
clear(){
|
|
44
|
-
return this.cache.clear();
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
keys(){
|
|
48
|
-
return this.cache.keys();
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
values(){
|
|
52
|
-
return this.cache.values();
|
|
53
|
-
}
|
|
54
|
-
}
|
package/src/memory.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* @Author: baozhoutao@steedos.com
|
|
3
|
-
* @Date: 2022-06-10 09:32:23
|
|
4
|
-
* @LastEditors: baozhoutao@steedos.com
|
|
5
|
-
* @LastEditTime: 2022-06-14 19:08:50
|
|
6
|
-
* @Description:
|
|
7
|
-
*/
|
|
8
|
-
import { keys, values } from 'lodash'
|
|
9
|
-
export class MemoryCacher {
|
|
10
|
-
private cache: any;
|
|
11
|
-
|
|
12
|
-
constructor(){
|
|
13
|
-
this.cache = {};
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
get(key: string){
|
|
17
|
-
return this.cache[key];
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
delete(key: string){
|
|
21
|
-
delete this.cache[key]
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
set(key: string, data: any){
|
|
25
|
-
this.cache[key] = data;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
clear(){
|
|
29
|
-
this.cache = {}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
keys(){
|
|
33
|
-
return keys(this.cache);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
values(){
|
|
37
|
-
return values(this.cache);
|
|
38
|
-
}
|
|
39
|
-
}
|
package/tsconfig.json
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"outDir": "./lib",
|
|
4
|
-
"target": "es5",
|
|
5
|
-
"module": "commonjs",
|
|
6
|
-
"moduleResolution": "node",
|
|
7
|
-
"importHelpers": true,
|
|
8
|
-
"emitDecoratorMetadata": true,
|
|
9
|
-
"experimentalDecorators": true,
|
|
10
|
-
"sourceMap": true,
|
|
11
|
-
"noImplicitAny": false,
|
|
12
|
-
"declaration": true,
|
|
13
|
-
"noFallthroughCasesInSwitch": true,
|
|
14
|
-
//"noImplicitReturns": true,
|
|
15
|
-
"stripInternal": true,
|
|
16
|
-
"pretty": true,
|
|
17
|
-
"noUnusedLocals": true,
|
|
18
|
-
"downlevelIteration": true,
|
|
19
|
-
"strictNullChecks": false,
|
|
20
|
-
"skipLibCheck": true,
|
|
21
|
-
"lib": [
|
|
22
|
-
"es5",
|
|
23
|
-
"es6",
|
|
24
|
-
"es2015",
|
|
25
|
-
"es2016",
|
|
26
|
-
"es2017",
|
|
27
|
-
"esnext"
|
|
28
|
-
],
|
|
29
|
-
},
|
|
30
|
-
"include": [
|
|
31
|
-
"./src/**/*"
|
|
32
|
-
],
|
|
33
|
-
"exclude": [
|
|
34
|
-
"../../node_modules/"
|
|
35
|
-
]
|
|
36
|
-
}
|