Skip to content

[BUG v5.0.0] TypeError: Cannot convert undefined or null to object on get operation #151

@StefanoSega

Description

@StefanoSega

With the same code that used to work with v4.x.x:

const NodeCache = require('node-cache');

const cacheSsr = new NodeCache({
  stdTTL: 5,
  checkperiod: 0,
});

module.exports = cacheSsr;
export class SsrCache {
  private _cache: any;

  constructor() {
    this._cache = require('./cacheSsr');
  }

  get(key) {
    const cacheSsr = this._cache;

    return cacheSsr.get(key);
  }
}
import { SsrCache } from './ssrHelper';

const ssrCache = new SsrCache();

const cachedData = ssrCache.get('key');

it returns the error

TypeError: Cannot convert undefined or null to object
    at Function.keys (<anonymous>)
    at NodeCache._getValLength (webpack:///./node_modules/node-cache/lib/node_cache.js?:690:56)
    at NodeCache.del (webpack:///./node_modules/node-cache/lib/node_cache.js?:461:38)
    at NodeCache._check (webpack:///./node_modules/node-cache/lib/node_cache.js?:600:18)
    at NodeCache.get (webpack:///./node_modules/node-cache/lib/node_cache.js?:332:46)
    at SsrCache.get

mind that for sure in the cache there's no value for that key

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions