@autofleet/matmon 1.0.2-beta-1 → 1.0.2-beta-2

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.
@@ -6,6 +6,7 @@ declare class RedisCache {
6
6
  private locks;
7
7
  private baseTTL;
8
8
  private lockRetries;
9
+ private useLock;
9
10
  constructor(options: any);
10
11
  get(key: any): Promise<any>;
11
12
  set(key: any, value: any): Promise<void>;
@@ -37,19 +37,22 @@ class RedisCache {
37
37
  this.lockDuration = (_c = options.lockDuration) !== null && _c !== void 0 ? _c : DEFAULT_LOCK_DURATION;
38
38
  this.baseTTL = (_d = options.ttl) !== null && _d !== void 0 ? _d : DEFAULT_BASE_TTL;
39
39
  this.locks = {};
40
+ this.useLock = !!options.useLock;
40
41
  }
41
42
  get(key) {
42
43
  return __awaiter(this, void 0, void 0, function* () {
43
- let lock;
44
- try {
45
- // Try to lock the key.
46
- lock = yield this.lock(key);
47
- }
48
- catch (err) {
49
- throw new errors_1.RedisLockError('Failed to lock key', err, key);
44
+ if (this.useLock) {
45
+ let lock;
46
+ try {
47
+ // Try to lock the key.
48
+ lock = yield this.lock(key);
49
+ }
50
+ catch (err) {
51
+ throw new errors_1.RedisLockError('Failed to lock key', err, key);
52
+ }
53
+ // If the lock did not fail, add it to a locks dictionary.
54
+ this.locks[key] = lock;
50
55
  }
51
- // If the lock did not fail, add it to a locks dictionary.
52
- this.locks[key] = lock;
53
56
  let value;
54
57
  try {
55
58
  // Try to get the value from redis.
@@ -66,6 +69,9 @@ class RedisCache {
66
69
  const ttl = parseInt(String(this.baseTTL * (Math.random() + 1)), 10);
67
70
  try {
68
71
  yield this.client.setAsync(key, JSON.stringify(value), 'EX', ttl);
72
+ if (this.locks[key]) {
73
+ yield this.locks[key]();
74
+ }
69
75
  }
70
76
  catch (err) {
71
77
  throw new errors_1.RedisCacheError('Failed to set a key-value pair', err);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autofleet/matmon",
3
- "version": "1.0.2-beta-1",
3
+ "version": "1.0.2-beta-2",
4
4
  "description": "manage cache",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",