@steedos/cachers 2.2.41

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/LICENSE.txt ADDED
@@ -0,0 +1,25 @@
1
+ Steedos Licensing
2
+
3
+ SOFTWARE LICENSING
4
+
5
+ To determine under which license you may use a file from the Steedos source code,
6
+ please resort to the header of that file.
7
+
8
+ If the file has no header, the following rules apply
9
+ 1. project templates are licensed under MIT, see License.MIT.txt
10
+ 2. enterprise features are licensed under Steedos Enterprise Terms, see License.enterprise.txt
11
+ 3. source code that is neither (1) nor (2) is licensed under AGPL, see License.AGPL.txt
12
+
13
+ On request, licenses under different terms are available.
14
+
15
+ Project templates can be found in the folders steedos-projects/
16
+
17
+ Source code of enterprise features are files that
18
+ * are in folders named "ee" or start with "ee_", or in subfolders of such folders.
19
+ * contain the strings "ee_" in its filename name.
20
+ The files can be found by running the command `find . -iname ee -or -iname "*_ee*" -or -iname "*ee_*"`
21
+
22
+ STEEDOS TRADEMARK GUIDELINES
23
+
24
+ Your use of the mark Steedos is subject to Steedos, Inc's prior written approval. For trademark approval or any questions
25
+ you have about using these trademarks, please email zhuangjianguo@steedos.com
package/README.md ADDED
@@ -0,0 +1,2 @@
1
+ ## 功能说明
2
+ - 此包用于系统国际化翻译功能
package/lib/index.d.ts ADDED
@@ -0,0 +1,3 @@
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[];
package/lib/index.js ADDED
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ /*
3
+ * @Author: baozhoutao@steedos.com
4
+ * @Date: 2022-06-09 15:03:56
5
+ * @LastEditors: baozhoutao@steedos.com
6
+ * @LastEditTime: 2022-06-10 11:16:07
7
+ * @Description:
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.getCacherNames = exports.clearCacher = exports.getCacher = void 0;
11
+ var CACHER_MAP = {};
12
+ var memory_1 = require("./memory");
13
+ var memory_lru_1 = require("./memory-lru");
14
+ var getCacher = function (name, options) {
15
+ if (!CACHER_MAP[name]) {
16
+ if (name.startsWith('lru.')) {
17
+ CACHER_MAP[name] = new memory_lru_1.MemoryLRUCacher(options);
18
+ }
19
+ else {
20
+ CACHER_MAP[name] = new memory_1.MemoryCacher();
21
+ }
22
+ }
23
+ return CACHER_MAP[name];
24
+ };
25
+ exports.getCacher = getCacher;
26
+ var clearCacher = function (name) {
27
+ if (CACHER_MAP[name]) {
28
+ CACHER_MAP[name].clear();
29
+ }
30
+ };
31
+ exports.clearCacher = clearCacher;
32
+ var getCacherNames = function () {
33
+ return Object.keys(CACHER_MAP);
34
+ };
35
+ exports.getCacherNames = getCacherNames;
36
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAGH,IAAM,UAAU,GAAG,EAAE,CAAC;AAEtB,mCAAwC;AACxC,2CAA8C;AAEvC,IAAM,SAAS,GAAG,UAAU,IAAY,EAAE,OAAa;IAC1D,IAAG,CAAC,UAAU,CAAC,IAAI,CAAC,EAAC;QACjB,IAAG,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,EAAC;YACvB,UAAU,CAAC,IAAI,CAAC,GAAG,IAAI,4BAAe,CAAC,OAAO,CAAC,CAAC;SACnD;aAAI;YACD,UAAU,CAAC,IAAI,CAAC,GAAG,IAAI,qBAAY,EAAE,CAAC;SACzC;KACJ;IACD,OAAO,UAAU,CAAC,IAAI,CAAC,CAAC;AAC5B,CAAC,CAAA;AATY,QAAA,SAAS,aASrB;AAEM,IAAM,WAAW,GAAG,UAAU,IAAqB;IACtD,IAAG,UAAU,CAAC,IAAI,CAAC,EAAC;QAChB,UAAU,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,CAAC;KAC5B;AACL,CAAC,CAAA;AAJY,QAAA,WAAW,eAIvB;AAEM,IAAM,cAAc,GAAG;IAC1B,OAAO,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;AACnC,CAAC,CAAA;AAFY,QAAA,cAAc,kBAE1B"}
@@ -0,0 +1,9 @@
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
+ del(key: string): any;
8
+ clear(): any;
9
+ }
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MemoryLRUCacher = void 0;
4
+ /*
5
+ * @Author: baozhoutao@steedos.com
6
+ * @Date: 2022-06-10 09:33:03
7
+ * @LastEditors: baozhoutao@steedos.com
8
+ * @LastEditTime: 2022-06-10 10:41:29
9
+ * @Description:
10
+ */
11
+ var lodash_1 = require("lodash");
12
+ var LRU = require('lru-cache');
13
+ var defaultOptions = {
14
+ max: 5000,
15
+ ttl: null,
16
+ keygen: null,
17
+ maxParamsLength: null
18
+ };
19
+ var MemoryLRUCacher = /** @class */ (function () {
20
+ function MemoryLRUCacher(opts) {
21
+ this.opts = (0, lodash_1.defaultsDeep)(opts, defaultOptions);
22
+ this.cache = new LRU({
23
+ max: this.opts.max,
24
+ maxAge: this.opts.ttl ? this.opts.ttl * 1000 : null,
25
+ updateAgeOnGet: !!this.opts.ttl
26
+ });
27
+ }
28
+ MemoryLRUCacher.prototype.get = function (key) {
29
+ return this.cache.get(key);
30
+ };
31
+ MemoryLRUCacher.prototype.set = function (key, data, opt) {
32
+ return this.cache.set(key, data, opt);
33
+ };
34
+ MemoryLRUCacher.prototype.del = function (key) {
35
+ return this.cache.del(key);
36
+ };
37
+ MemoryLRUCacher.prototype.clear = function () {
38
+ return this.cache.clear();
39
+ };
40
+ return MemoryLRUCacher;
41
+ }());
42
+ exports.MemoryLRUCacher = MemoryLRUCacher;
43
+ //# sourceMappingURL=memory-lru.js.map
@@ -0,0 +1 @@
1
+ {"version":3,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 @@
1
+ export declare class MemoryCacher {
2
+ private cache;
3
+ constructor();
4
+ get(key: string): any;
5
+ del(key: string): void;
6
+ set(key: string, data: any): void;
7
+ clear(): void;
8
+ }
package/lib/memory.js ADDED
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MemoryCacher = void 0;
4
+ /*
5
+ * @Author: baozhoutao@steedos.com
6
+ * @Date: 2022-06-10 09:32:23
7
+ * @LastEditors: baozhoutao@steedos.com
8
+ * @LastEditTime: 2022-06-10 09:48:37
9
+ * @Description:
10
+ */
11
+ var MemoryCacher = /** @class */ (function () {
12
+ function MemoryCacher() {
13
+ this.cache = {};
14
+ }
15
+ MemoryCacher.prototype.get = function (key) {
16
+ return this.cache[key];
17
+ };
18
+ MemoryCacher.prototype.del = function (key) {
19
+ delete this.cache[key];
20
+ };
21
+ MemoryCacher.prototype.set = function (key, data) {
22
+ this.cache[key] = data;
23
+ };
24
+ MemoryCacher.prototype.clear = function () {
25
+ this.cache = {};
26
+ };
27
+ return MemoryCacher;
28
+ }());
29
+ exports.MemoryCacher = MemoryCacher;
30
+ //# sourceMappingURL=memory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory.js","sourceRoot":"","sources":["../src/memory.ts"],"names":[],"mappings":";;;AAAA;;;;;;GAMG;AACH;IAGI;QACI,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC;IACpB,CAAC;IAED,0BAAG,GAAH,UAAI,GAAW;QACX,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC3B,CAAC;IAED,0BAAG,GAAH,UAAI,GAAW;QACX,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IAC1B,CAAC;IAED,0BAAG,GAAH,UAAI,GAAW,EAAE,IAAS;QACtB,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;IAC3B,CAAC;IAED,4BAAK,GAAL;QACI,IAAI,CAAC,KAAK,GAAG,EAAE,CAAA;IACnB,CAAC;IACL,mBAAC;AAAD,CAAC,AAtBD,IAsBC;AAtBY,oCAAY"}
package/package.json ADDED
@@ -0,0 +1,23 @@
1
+ {
2
+ "name": "@steedos/cachers",
3
+ "private": false,
4
+ "version": "2.2.41",
5
+ "description": "",
6
+ "main": "lib/index.js",
7
+ "scripts": {
8
+ "compile": "tsc",
9
+ "prepare": "tsc"
10
+ },
11
+ "author": "",
12
+ "license": "ISC",
13
+ "dependencies": {
14
+ "lru-cache": "^7.10.1"
15
+ },
16
+ "devDependencies": {
17
+ "typescript": "3.5.3"
18
+ },
19
+ "publishConfig": {
20
+ "access": "public"
21
+ },
22
+ "gitHead": "ded6a9013bea822bc4cf81c98e60a3d829bed858"
23
+ }
package/src/index.ts ADDED
@@ -0,0 +1,34 @@
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
+ }
@@ -0,0 +1,46 @@
1
+ /*
2
+ * @Author: baozhoutao@steedos.com
3
+ * @Date: 2022-06-10 09:33:03
4
+ * @LastEditors: baozhoutao@steedos.com
5
+ * @LastEditTime: 2022-06-10 10:41:29
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
+ del(key: string){
40
+ return this.cache.del(key);
41
+ }
42
+
43
+ clear(){
44
+ return this.cache.clear();
45
+ }
46
+ }
package/src/memory.ts ADDED
@@ -0,0 +1,30 @@
1
+ /*
2
+ * @Author: baozhoutao@steedos.com
3
+ * @Date: 2022-06-10 09:32:23
4
+ * @LastEditors: baozhoutao@steedos.com
5
+ * @LastEditTime: 2022-06-10 09:48:37
6
+ * @Description:
7
+ */
8
+ export class MemoryCacher {
9
+ private cache: any;
10
+
11
+ constructor(){
12
+ this.cache = {};
13
+ }
14
+
15
+ get(key: string){
16
+ return this.cache[key];
17
+ }
18
+
19
+ del(key: string){
20
+ delete this.cache[key]
21
+ }
22
+
23
+ set(key: string, data: any){
24
+ this.cache[key] = data;
25
+ }
26
+
27
+ clear(){
28
+ this.cache = {}
29
+ }
30
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,36 @@
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
+ }