@graphql-mesh/cache-inmemory-lru 0.5.31 → 0.5.32-alpha-044ef7368.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/index.d.ts CHANGED
@@ -1,9 +1,7 @@
1
1
  import { KeyValueCache, KeyValueCacheSetOptions } from '@graphql-mesh/types';
2
2
  export default class InMemoryLRUCache<V = any> implements KeyValueCache<V> {
3
3
  private cacheIdentifier;
4
- constructor({ max }?: {
5
- max?: number;
6
- });
4
+ private nextTick;
7
5
  get(key: string): Promise<V>;
8
6
  set(key: string, value: V, options?: KeyValueCacheSetOptions): Promise<void>;
9
7
  delete(key: string): Promise<void>;
package/index.js CHANGED
@@ -3,10 +3,16 @@
3
3
  const utils = require('@graphql-mesh/utils');
4
4
 
5
5
  class InMemoryLRUCache {
6
- constructor({ max = Infinity } = {}) {
6
+ constructor() {
7
7
  this.cacheIdentifier = Date.now();
8
8
  }
9
+ nextTick() {
10
+ // Make sure this is scheduled for next tick because LRU Cache is synchronous
11
+ // This helps for testing multiple Mesh instances pointing to the same cache
12
+ return new Promise(resolve => setTimeout(resolve));
13
+ }
9
14
  async get(key) {
15
+ await this.nextTick();
10
16
  const entry = utils.globalLruCache.get(`${this.cacheIdentifier}-${key}`);
11
17
  if ((entry === null || entry === void 0 ? void 0 : entry.expiresAt) && Date.now() > entry.expiresAt) {
12
18
  utils.globalLruCache.delete(key);
@@ -15,12 +21,14 @@ class InMemoryLRUCache {
15
21
  return entry === null || entry === void 0 ? void 0 : entry.value;
16
22
  }
17
23
  async set(key, value, options) {
24
+ await this.nextTick();
18
25
  utils.globalLruCache.set(`${this.cacheIdentifier}-${key}`, {
19
26
  expiresAt: (options === null || options === void 0 ? void 0 : options.ttl) ? Date.now() + options.ttl * 1000 : Infinity,
20
27
  value,
21
28
  });
22
29
  }
23
30
  async delete(key) {
31
+ await this.nextTick();
24
32
  utils.globalLruCache.delete(`${this.cacheIdentifier}-${key}`);
25
33
  }
26
34
  }
package/index.mjs CHANGED
@@ -1,10 +1,16 @@
1
1
  import { globalLruCache } from '@graphql-mesh/utils';
2
2
 
3
3
  class InMemoryLRUCache {
4
- constructor({ max = Infinity } = {}) {
4
+ constructor() {
5
5
  this.cacheIdentifier = Date.now();
6
6
  }
7
+ nextTick() {
8
+ // Make sure this is scheduled for next tick because LRU Cache is synchronous
9
+ // This helps for testing multiple Mesh instances pointing to the same cache
10
+ return new Promise(resolve => setTimeout(resolve));
11
+ }
7
12
  async get(key) {
13
+ await this.nextTick();
8
14
  const entry = globalLruCache.get(`${this.cacheIdentifier}-${key}`);
9
15
  if ((entry === null || entry === void 0 ? void 0 : entry.expiresAt) && Date.now() > entry.expiresAt) {
10
16
  globalLruCache.delete(key);
@@ -13,12 +19,14 @@ class InMemoryLRUCache {
13
19
  return entry === null || entry === void 0 ? void 0 : entry.value;
14
20
  }
15
21
  async set(key, value, options) {
22
+ await this.nextTick();
16
23
  globalLruCache.set(`${this.cacheIdentifier}-${key}`, {
17
24
  expiresAt: (options === null || options === void 0 ? void 0 : options.ttl) ? Date.now() + options.ttl * 1000 : Infinity,
18
25
  value,
19
26
  });
20
27
  }
21
28
  async delete(key) {
29
+ await this.nextTick();
22
30
  globalLruCache.delete(`${this.cacheIdentifier}-${key}`);
23
31
  }
24
32
  }
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@graphql-mesh/cache-inmemory-lru",
3
- "version": "0.5.31",
3
+ "version": "0.5.32-alpha-044ef7368.0",
4
4
  "sideEffects": false,
5
5
  "peerDependencies": {
6
6
  "graphql": "*"
7
7
  },
8
8
  "dependencies": {
9
9
  "@graphql-mesh/types": "0.56.0",
10
- "@graphql-mesh/utils": "0.22.1"
10
+ "@graphql-mesh/utils": "0.22.2-alpha-044ef7368.0"
11
11
  },
12
12
  "license": "MIT",
13
13
  "main": "index.js",