Skip to content

Setting undefined as value, getting null back (version 5.1.2) #330

@meszaros-lajos-gyorgy

Description

@meszaros-lajos-gyorgy

I'm using node-cache 5.1.2 and this is the little example code that I have:

import NodeCache from 'node-cache'

const cache = new NodeCache({
  stdTTL: 900,
  checkperiod: 900 / 5,
  useClones: false,
})

cache.set('hello', undefined)
const restored = cache.get('hello') // incorrectly returns null

I found this already closed issue, don't know whether it is caused by same thing, but the issue still definitely persists.

If anyone finds this issue my current workaround is to wrap every data that I store into an object, like this:

cache.set('workaround', { value: undefined })
const restored = cache.get('workaround').value // correctly returns undefined

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