@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 CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@steedos/cachers",
3
3
  "private": false,
4
- "version": "2.2.51-beta.1",
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": "edeb1c70d34159e3caac697f9e207c2ca98d8d00"
22
+ "gitHead": "c324c40fa8facd3bf73a51e8c417293a9349f9fb"
23
23
  }
package/lib/index.d.ts DELETED
@@ -1,3 +0,0 @@
1
- export declare const getCacher: (name: string, options?: any) => any;
2
- export declare const clearCacher: (name: string | number) => void;
3
- export declare const getCacherNames: () => string[];
@@ -1,11 +0,0 @@
1
- export declare class MemoryLRUCacher {
2
- private cache;
3
- opts: any;
4
- constructor(opts: any);
5
- get(key: string): any;
6
- set(key: string, data: any, opt?: any): any;
7
- delete(key: string): any;
8
- clear(): any;
9
- keys(): any;
10
- values(): any;
11
- }
package/lib/memory.d.ts DELETED
@@ -1,10 +0,0 @@
1
- export declare class MemoryCacher {
2
- private cache;
3
- constructor();
4
- get(key: string): any;
5
- delete(key: string): void;
6
- set(key: string, data: any): void;
7
- clear(): void;
8
- keys(): string[];
9
- values(): any[];
10
- }
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
- }