@autofleet/matmon 2.0.5 → 2.0.7

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/lib/cache.js CHANGED
@@ -49,6 +49,11 @@ const getMutexByCacheKey = (key) => {
49
49
  }
50
50
  return MUTEX_MAP[key];
51
51
  };
52
+ const deleteMutexByCacheKey = (key) => {
53
+ if (MUTEX_MAP[key]) {
54
+ delete MUTEX_MAP[key];
55
+ }
56
+ };
52
57
  exports.getNewLRU = (lifeTimeInSec, size) => new lru_cache_1.default(getOptions({
53
58
  lifeTimeInSec,
54
59
  size,
@@ -70,12 +75,14 @@ exports.getWithCacheSupport = ({ cacheKey, cacheGet, cacheSet, fetching, skipCac
70
75
  else {
71
76
  // logger.info('get value from cache');
72
77
  }
78
+ deleteMutexByCacheKey(cacheKey);
73
79
  }));
74
80
  // retry without locking if failed
75
81
  }
76
82
  catch (e) {
77
83
  valueToReturn = yield fetching();
78
84
  yield cacheSet(valueToReturn);
85
+ deleteMutexByCacheKey(cacheKey);
79
86
  }
80
87
  return valueToReturn;
81
88
  });
@@ -47,6 +47,14 @@ class RedisCache {
47
47
  get(key) {
48
48
  return __awaiter(this, void 0, void 0, function* () {
49
49
  const keyWithPrefix = KEY_PREFIX + key;
50
+ let value;
51
+ try {
52
+ // Try to get the value from redis.
53
+ value = yield this.client.getAsync(keyWithPrefix);
54
+ }
55
+ catch (err) {
56
+ throw new errors_1.RedisCacheError('Failed to get a value', err);
57
+ }
50
58
  if (this.useLock) {
51
59
  let lock;
52
60
  try {
@@ -59,14 +67,6 @@ class RedisCache {
59
67
  // If the lock did not fail, add it to a locks dictionary.
60
68
  this.locks[keyWithPrefix] = lock;
61
69
  }
62
- let value;
63
- try {
64
- // Try to get the value from redis.
65
- value = yield this.client.getAsync(keyWithPrefix);
66
- }
67
- catch (err) {
68
- throw new errors_1.RedisCacheError('Failed to get a value', err);
69
- }
70
70
  return JSON.parse(value);
71
71
  });
72
72
  }
@@ -78,6 +78,7 @@ class RedisCache {
78
78
  yield this.client.setAsync(keyWithPrefix, JSON.stringify(value), 'EX', ttl);
79
79
  if (this.locks[keyWithPrefix]) {
80
80
  yield this.locks[keyWithPrefix]();
81
+ delete this.locks[keyWithPrefix];
81
82
  }
82
83
  }
83
84
  catch (err) {
@@ -91,6 +92,7 @@ class RedisCache {
91
92
  try {
92
93
  if (this.locks[keyWithPrefix]) {
93
94
  yield this.locks[keyWithPrefix]();
95
+ delete this.locks[keyWithPrefix];
94
96
  }
95
97
  yield this.client.delAsync(keyWithPrefix);
96
98
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autofleet/matmon",
3
- "version": "2.0.5",
3
+ "version": "2.0.7",
4
4
  "description": "manage cache",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",