{"record":{"id":"09bd28eb39096c6b","repo":"nodejs/node","slug":"memorycachestore-options-maxentrysize-must-be-a-no","errorCode":null,"errorMessage":"MemoryCacheStore options.maxEntrySize must be a non-negative integer","messagePattern":"MemoryCacheStore options\\.maxEntrySize must be a non-negative integer","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"deps/undici/src/lib/cache/memory-cache-store.js","lineNumber":66,"sourceCode":"\n      if (opts.maxSize !== undefined) {\n        if (\n          typeof opts.maxSize !== 'number' ||\n          !Number.isInteger(opts.maxSize) ||\n          opts.maxSize < 0\n        ) {\n          throw new TypeError('MemoryCacheStore options.maxSize must be a non-negative integer')\n        }\n        this.#maxSize = opts.maxSize\n      }\n\n      if (opts.maxEntrySize !== undefined) {\n        if (\n          typeof opts.maxEntrySize !== 'number' ||\n          !Number.isInteger(opts.maxEntrySize) ||\n          opts.maxEntrySize < 0\n        ) {\n          throw new TypeError('MemoryCacheStore options.maxEntrySize must be a non-negative integer')\n        }\n        this.#maxEntrySize = opts.maxEntrySize\n      }\n    }\n  }\n\n  /**\n   * Get the current size of the cache in bytes\n   * @returns {number} The current size of the cache in bytes\n   */\n  get size () {\n    return this.#size\n  }\n\n  /**\n   * Check if the cache is full (either max size or max count reached)\n   * @returns {boolean} True if the cache is full, false otherwise\n   */","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/nodejs/node/blob/1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e/deps/undici/src/lib/cache/memory-cache-store.js#L48-L84","documentation":"Thrown by the MemoryCacheStore constructor when opts.maxEntrySize is defined but is not a non-negative integer. maxEntrySize caps the size of a single cached entry in bytes (default 5 MB / 5242880); entries larger than this are not cached. Floats, negatives, strings, NaN, and Infinity are rejected.","triggerScenarios":"Passing maxEntrySize: 2.5e6 (float), maxEntrySize: -1, maxEntrySize: '5242880' (string), or maxEntrySize: Infinity.","commonSituations":"Setting a per-entry cap computed from MB with a fractional multiplier; env-string config not parsed; using Infinity (disallowed — omit to allow any size up to maxSize).","solutions":["Pass a non-negative integer byte count: { maxEntrySize: 5 * 1024 * 1024 }.","Validate parsed config with Number.isInteger before assigning.","Omit maxEntrySize if you want the default per-entry cap or no cap beyond maxSize."],"exampleFix":"// before\nnew MemoryCacheStore({ maxEntrySize: 2.5 * 1024 * 1024 }) // float\n\n// after\nnew MemoryCacheStore({ maxEntrySize: Math.floor(2.5 * 1024 * 1024) })","handlingStrategy":"validation","validationCode":"function optInt(v) {\n  const n = Number(v)\n  if (!Number.isInteger(n) || n < 0) throw new TypeError('must be a non-negative integer')\n  return n\n}\n// new MemoryCacheStore({ maxEntrySize: optInt(config.entryBytes) })","typeGuard":"function isNonNegInt(v) { return Number.isInteger(v) && v >= 0 }","tryCatchPattern":null,"preventionTips":["Use integer byte counts for maxEntrySize; floor any fractional MB math.","Validate with Number.isInteger before constructing the store.","Omit maxEntrySize to rely on the default 5 MB per-entry cap."],"tags":["undici","cache","memory-cache-store","validation","configuration"],"backgroundTag":null,"analyzedSha":"1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e","analyzedAt":"2026-08-13T00:53:24.642Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}