Skip to content

Setting CACHE_MEMORY_MAX env var crashes app #774

Description

@abid-mujtaba

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions