@adaptivestone/framework 3.1.1 → 3.2.0

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/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ### 3.2.0
2
+
3
+ [UPDATE] updated deps
4
+ [NEW] cache.removeKey(key) - function to remove key from cache
5
+
1
6
  ### 3.1.1
2
7
 
3
8
  [UPDATE] updated deps
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adaptivestone/framework",
3
- "version": "3.1.1",
3
+ "version": "3.2.0",
4
4
  "description": "Adaptive stone node js framework",
5
5
  "main": "src/index.js",
6
6
  "engines": {
@@ -6,6 +6,13 @@ declare class Cache extends Base {
6
6
 
7
7
  constructor(app: Server['app']);
8
8
 
9
+ /**
10
+ * As framework support namespaces all key for cache go through this function
11
+ * Function return new key with added namespace
12
+ * @param key key to add namespace
13
+ */
14
+ getKeyWithNameSpace(key: String): String;
15
+
9
16
  /**
10
17
  * Get value from cache. Set and get if not eists
11
18
  * @param key key to check
@@ -17,6 +24,12 @@ declare class Cache extends Base {
17
24
  onNotFound: () => Promise<any>,
18
25
  storeTime: number,
19
26
  ): Promise<any>;
27
+
28
+ /**
29
+ * Remove key from cache
30
+ * @param key key to remove
31
+ */
32
+ removeKey(key: String): Promise<number>;
20
33
  }
21
34
 
22
35
  export = Cache;
@@ -28,11 +28,15 @@ class Cache extends Base {
28
28
  this.promiseMapping = new Map();
29
29
  }
30
30
 
31
+ getKeyWithNameSpace(key) {
32
+ return `${this.redisNamespace}-${key}`;
33
+ }
34
+
31
35
  async getSetValue(keyValue, onNotFound, storeTime = 60 * 5) {
32
36
  if (!this.redisClient.isOpen) {
33
37
  await this.redisClient.connect();
34
38
  }
35
- const key = `${this.redisNamespace}-${keyValue}`;
39
+ const key = this.getKeyWithNameSpace(keyValue);
36
40
  // 5 mins default
37
41
  let resolve = null;
38
42
  let reject = null;
@@ -81,6 +85,14 @@ class Cache extends Base {
81
85
  return result;
82
86
  }
83
87
 
88
+ async removeKey(keyValue) {
89
+ if (!this.redisClient.isOpen) {
90
+ await this.redisClient.connect();
91
+ }
92
+ const key = this.getKeyWithNameSpace(keyValue);
93
+ return this.redisClient.del(key);
94
+ }
95
+
84
96
  static get loggerGroup() {
85
97
  return 'Cache_';
86
98
  }