@autofleet/node-common 1.4.8 → 1.5.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autofleet/node-common",
3
- "version": "1.4.8",
3
+ "version": "1.5.0",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "coverage": "jest --coverage --forceExit --runInBand",
@@ -37,7 +37,6 @@
37
37
  "portfinder": "^1.0.13",
38
38
  "qs": "^6.5.2",
39
39
  "timekeeper": "^2.1.2",
40
- "weak": "^1.0.1",
41
40
  "winston": "^3.0.0",
42
41
  "ws": "^5.2.1"
43
42
  },
package/settings/index.js CHANGED
@@ -45,12 +45,15 @@ class SettingsManager {
45
45
  });
46
46
  }
47
47
 
48
+ calcRandomTtl() {
49
+ return this.ttl + (1 + Math.random());
50
+ }
51
+
48
52
  async get(key, defaultValue, labels = [], { timeout = 1000 } = {}) {
49
53
  if (typeof defaultValue === 'undefined') {
50
54
  throw new Error('Can\'t get a key without defaultValue');
51
55
  }
52
56
  if (!keysMap[key]) {
53
- // TODO: Throw error here after done with mapping all keys
54
57
  logger.error(`Try to get settings for unknown key: ${key}`);
55
58
  }
56
59
 
@@ -94,13 +97,13 @@ class SettingsManager {
94
97
  this.settingsCache.del(cacheKey);
95
98
  throw e;
96
99
  }
97
- this.settingsCache.set(cacheKey, returnValue, this.ttl);
100
+ this.settingsCache.set(cacheKey, returnValue, this.calcRandomTtl());
98
101
  return returnValue;
99
102
  }
100
103
 
101
104
  setLocal(key, labels, value) {
102
105
  const cacheKey = `${key}_${JSON.stringify(labels)}`;
103
- this.settingsCache.set(cacheKey, value, this.ttl);
106
+ this.settingsCache.set(cacheKey, value, this.calcRandomTtl());
104
107
  }
105
108
 
106
109
  flush() {