mergeability/mergeable

Setting CACHE_MEMORY_MAX env var crashes app

Opened this issue · 0 comments

I set the CACHE_MEMORY_MAX env var to 2000 and on application startup I got:

/mergeable/node_modules/lru-cache/index.js:36
      throw new TypeError('max must be a non-negative number')
            ^

TypeError: max must be a non-negative number
    at new LRUCache (/mergeable/node_modules/lru-cache/index.js:36:13)
    at memoryStore (/mergeable/node_modules/cache-manager/lib/stores/memory.js:43:20)
    at Object.create (/mergeable/node_modules/cache-manager/lib/stores/memory.js:235:16)
    at Object.caching (/mergeable/node_modules/cache-manager/lib/caching.js:32:47)
    at new Cache (/mergeable/lib/cache/cache.js:22:35)
    at Object.<anonymous> (/mergeable/lib/configuration/configuration.js:8:22)
    at Module._compile (node:internal/modules/cjs/loader:1469:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1548:10)
    at Module.load (node:internal/modules/cjs/loader:1288:32)
    at Module._load (node:internal/modules/cjs/loader:1104:12)

Looks like this can be fixed by parsing the env var as an int using something like:

function getMemoryMax () {
  return process.env.CACHE_MEMORY_MAX ? parseInt(process.env.CACHE_MEMORY_MAX) : undefined
}

Happy to open a PR.