@smartico/public-api 0.0.201 → 0.0.202

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@smartico/public-api",
3
- "version": "0.0.201",
3
+ "version": "0.0.202",
4
4
  "description": "Smartico public API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/NodeCache.ts CHANGED
@@ -1,17 +1,17 @@
1
1
  class NodeCache {
2
- private static ttlChecker: NodeJS.Timeout;
2
+ private ttlChecker: NodeJS.Timeout;
3
3
 
4
- private static cache: { [key: string]: any } = {};
4
+ private cache: { [key: string]: any } = {};
5
5
 
6
- constructor() {
7
- if (NodeCache.ttlChecker === undefined) {
8
- NodeCache.ttlChecker = setInterval(() => {
6
+ constructor() {
7
+ if (this.ttlChecker === undefined) {
8
+ this.ttlChecker = setInterval(() => {
9
9
  const now = new Date().getTime();
10
- for (const key in NodeCache.cache) {
11
- if (NodeCache.cache.hasOwnProperty(key)) {
12
- const o = NodeCache.cache[key];
10
+ for (const key in this.cache) {
11
+ if (this.cache.hasOwnProperty(key)) {
12
+ const o = this.cache[key];
13
13
  if (o.ttl < now) {
14
- delete NodeCache.cache[key];
14
+ delete this.cache[key];
15
15
  }
16
16
  }
17
17
  }
@@ -20,27 +20,31 @@ class NodeCache {
20
20
  }
21
21
 
22
22
  public get(key: string): any {
23
- const o = NodeCache.cache[key];
23
+ const o = this.cache[key];
24
24
  if (o !== undefined && o.ttl > new Date().getTime()) {
25
25
  return o.value;
26
26
  }
27
27
  }
28
28
 
29
29
  public set(key: string, value: any, ttlSeconds: number = 60) {
30
- NodeCache.cache[key] = {
30
+ this.cache[key] = {
31
31
  value,
32
32
  ttl: new Date().getTime() + ttlSeconds * 1000,
33
33
  };
34
34
  }
35
35
 
36
36
  public remove(key: string) {
37
- if (NodeCache.cache.hasOwnProperty(key)) {
38
- delete NodeCache.cache[key];
37
+ if (this.cache.hasOwnProperty(key)) {
38
+ delete this.cache[key];
39
39
  }
40
40
  }
41
41
 
42
42
  public flushAll() {
43
- NodeCache.cache = {};
43
+ this.cache = {};
44
+ if (this.ttlChecker) {
45
+ clearInterval(this.ttlChecker);
46
+ this.ttlChecker = undefined
47
+ }
44
48
  }
45
49
  }
46
50
 
package/src/OCache.ts CHANGED
@@ -63,6 +63,11 @@ export class OCache {
63
63
  }
64
64
 
65
65
  public static async clearAll() {
66
+ for (const cacheContext in this.cache) {
67
+ if (this.cache.hasOwnProperty(cacheContext)) {
68
+ this.cache[cacheContext].flushAll();
69
+ }
70
+ }
66
71
  this.cache = {};
67
72
  }
68
73
  }