node-cache icon indicating copy to clipboard operation
node-cache copied to clipboard

It costs too much time!!!!!!!!!

Open AdaJass opened this issue 2 years ago • 2 comments

if the setting value is complicate and large, it will slow too much!!!!!!!! there must be a big bug!!!!!!!!!!!!!!!!

AdaJass avatar Jul 05 '23 06:07 AdaJass

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

const MAKE_DATA_LENGTH = 100000

function randStr(length) {
    const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
    let result = '';  
    for (let i = 0; i < length; i++) {
      result += characters.charAt(Math.floor(Math.random() * characters.length));
    }  
    return result;
}

const fromCache = (key, loadFunction, param_list) => {
    if(Cache.has(key)){
        console.time('getcache')
        let r = Cache.get(key)
        console.timeEnd('getcache')
        return r;
    }else{
        console.time('make_data')
        let data=[]
        for(let i=0;i<MAKE_DATA_LENGTH;i++){  
            let tmp = {}
            for(let j=0;j<5;j++){
                tmp[randStr(10)] = randStr(10)    
            }                
            data.push(tmp)
        }
        for(let i=0;i<data.length;i++){
            data[i].json= {
                type: 'token_add',
                acc_id: 9627,     
                role_id: 0+i,
                create_time: '2023-07-05 14:29:09',
                info: {"v":176,"cur":0.93+i,"type":"img","note":"recharge"}
              }
        }

        console.timeEnd('make_data')
        console.time('making_cache')
        Cache.set(key, data, 60*15)
        console.timeEnd('making_cache')        
        return data;
    }
}

function test(){
    let r1 = fromCache('test')
    let r2 = fromCache('test')
    console.log('complete')
}

test()

Using this code, you will see how slow it runs!!!!!!!!!!!! the result on my computer is:

make_data: 1.344s
making_cache: 28.884s
getcache: 30.175s
complete

AdaJass avatar Jul 05 '23 07:07 AdaJass

#295 have you read the other issues and tried this?

sheldoncoates avatar Jul 09 '23 16:07 sheldoncoates