简体   繁体   中英

FATAL ERROR: v8::Object::SetInternalField() Internal field out of bounds on Node js using node-cache

I have a api export with a lot of data so I tried to used the node-cache so the api will be faster since take more than 2 min to get the data, I am new on this so I found the follow code: Notes: env node.js/express

const NodeCache = require("node-cache");
const axios = require('axios');
const myCache = new NodeCache({stdTTL:100000})
 axios.get('http://localhost:5000/test/example)
        .then(function (response) {
            console.log(response)
            myCache.set("exampleCache",response,10000);
            res.send(response)

Any suggestion or recommend will be great!

By default, the NodeCache module clones the object before saving it.

In your case, you're trying to cache the Axios response object, which cannot be cloned by NodeCache (it's a big and complex object), so you're getting the error.

Instead, I recommend cloning the HTTP response data (response.data), which is much smaller and clonable. Or, you can clone the whole Axios response object, like in your code example, but you need to set the option {useClones: false} during initialization of NodeCache, this way the NodeCache will save just the reference to the object.

The solution was using a buffer but since we had to many data, the increase the memory from the db was the solution

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM