Title: Cache key expired or removed throws with "Cannot read properties of undefined (reading 'v')" · Issue #329 · node-cache/node-cache · GitHub
Open Graph Title: Cache key expired or removed throws with "Cannot read properties of undefined (reading 'v')" · Issue #329 · node-cache/node-cache
X Title: Cache key expired or removed throws with "Cannot read properties of undefined (reading 'v')" · Issue #329 · node-cache/node-cache
Description: When using node-cache in a TypeScript/Node.js project, I encounter the following error when calling .get() or .del() on a key that is missing or expired: { "type": "TypeError", "message": "Cannot read properties of undefined (reading 'v'...
Open Graph Description: When using node-cache in a TypeScript/Node.js project, I encounter the following error when calling .get() or .del() on a key that is missing or expired: { "type": "TypeError", "message": "Cannot r...
X Description: When using node-cache in a TypeScript/Node.js project, I encounter the following error when calling .get() or .del() on a key that is missing or expired: { "type": "TypeError", ...
Opengraph URL: https://github.com/node-cache/node-cache/issues/329
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":" Cache key expired or removed throws with \"Cannot read properties of undefined (reading 'v')\"","articleBody":"When using node-cache in a TypeScript/Node.js project, I encounter the following error when calling .get() or .del() on a key that is missing or expired:\n\n```json\n{\n \"type\": \"TypeError\",\n \"message\": \"Cannot read properties of undefined (reading 'v')\",\n \"stack\":\n TypeError: Cannot read properties of undefined (reading 'v')\n at NodeCache._unwrap (/app/node_modules/node-cache/lib/node_cache.js:711:19)\n at NodeCache.get (/app/node_modules/node-cache/lib/node_cache.js:368:23)\n at setDocumentCache (file:///app/dist/utils/document.js:18:36)\n at newDocumentFromData (file:///app/dist/utils/document.js:34:9)\n at process.processTicksAndRejections (node:internal/process/task_queues:105:5)\n at async Object.getPdfMetadata (file:///app/dist/plugins/live-document-service.js:36:33)\n at async Object.\u003canonymous\u003e (file:///app/dist/routes/preview/pdf-metadata.js:86:19)\n }\n```\n\n#### Steps to Reproduce:\n\n1. Create a cache instance with `deleteOnExpire: false`\n2. Call .get() on a key that does not exist or has expired.\n3. The error occurs inside the library when it tries to access .v of undefined.\n\n```typescript\nconst documentCache = new NodeCache({\n stdTTL: 60 * 2, // 2 minutes\n useClones: false,\n deleteOnExpire: false,\n});\n\ndocumentCache.on(\"expired\", (key, pdfDocument) =\u003e {\n if (typeof pdfDocument?.cleanup === \"function\") {\n pdfDocument.cleanup();\n }\n documentCache.del(key);\n});\n\nfunction setDocumentCache(cacheKey: string, pdfDocument: PDFDocumentProxy) {\n const existing = documentCache.get\u003cPDFDocumentProxy\u003e(cacheKey);\n if (typeof existing?.cleanup === \"function\") {\n existing.cleanup();\n }\n documentCache.set(cacheKey, pdfDocument);\n}\n```\n\n#### Expected Behavior:\n\nCalling .get() on a missing or expired key should return undefined without throwing an error.\n\n#### Environment:\n\n- node-cache version: 5.1.2\n- Node.js version: lts-bullseye\n\n#### Additional Context:\n\nSeems to be triggered by the library’s internal _unwrap method.","author":{"url":"https://github.com/twrayden","@type":"Person","name":"twrayden"},"datePublished":"2025-10-08T07:10:08.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/329/node-cache/issues/329"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:80384305-9e14-aa08-901d-457f80937ada |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B5DC:2D3E84:1A4EFB7:2403333:6964BE44 |
| html-safe-nonce | 71680cb63ba5b589990da71020c0099e831f9e52d21a59cd4169e510386a37fa |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCNURDOjJEM0U4NDoxQTRFRkI3OjI0MDMzMzM6Njk2NEJFNDQiLCJ2aXNpdG9yX2lkIjoiNjgzODk2Mzk5NzI3NzIwODEzMiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | d2f1fd30e3a33881444e94956fa12fdf16e683dea5159ed2bcd1f1508ede539b |
| hovercard-subject-tag | issue:3494168109 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/node-cache/node-cache/329/issue_layout |
| twitter:image | https://opengraph.githubassets.com/1544c08c85023e556e4ec7c83280ad5ace89a7634516da90c27e34e637dbd27d/node-cache/node-cache/issues/329 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/1544c08c85023e556e4ec7c83280ad5ace89a7634516da90c27e34e637dbd27d/node-cache/node-cache/issues/329 |
| og:image:alt | When using node-cache in a TypeScript/Node.js project, I encounter the following error when calling .get() or .del() on a key that is missing or expired: { "type": "TypeError", "message": "Cannot r... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | twrayden |
| hostname | github.com |
| expected-hostname | github.com |
| None | 9917306ebdf5f9f30d13ede7b74f08a45b5f12b401ce3e4bfabd895ea0ca0ada |
| turbo-cache-control | no-preview |
| go-import | github.com/node-cache/node-cache git https://github.com/node-cache/node-cache.git |
| octolytics-dimension-user_id | 54621913 |
| octolytics-dimension-user_login | node-cache |
| octolytics-dimension-repository_id | 2599450 |
| octolytics-dimension-repository_nwo | node-cache/node-cache |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 2599450 |
| octolytics-dimension-repository_network_root_nwo | node-cache/node-cache |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 020ceddb26807bba62dcfb410905847d63243ff5 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width