使用Node JS中的节点caching模块,设置后无法获取数据

Node.js版本:v6.10.3操作系统:Windows

我正在尝试使用Node JS实现caching。 使用节点caching模块。 我使用下面的代码将数据设置为caching并从caching中获取数据。

const NodeCache = require( "node-cache" ); const myCache = new NodeCache( { stdTTL: 3000, checkperiod: 3000} ); obj = { my: "Special", variable: 42 }; myCache.set( "myKey", obj ); // Calling DB, fetch the data and set in to cache for first time when client requests. value = myCache.get( "myKey" ); console.log('value: ',value); console.log(JSON.stringify(myCache)); 

但是,一旦我设置了数据,下一次当我试图获取数据(没有设置数据,因为我已经设置),那么它给了我一个未定义的值。 当我打印caching时,我看不到该值(按照下面的示例,值是{我:“特殊”,variables:42})。 所以值不会被保存到caching中。 我提供了stdTTL为3000毫秒,所以数据应可用于3000毫秒,但它不可用于caching。

我是否需要使用TTL设置某些内容,或者是否有其他设置来获取caching中保存的值?