Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

It costs too much time!!!!!!!!! #309

Open
AdaJass opened this issue Jul 5, 2023 · 2 comments
Open

It costs too much time!!!!!!!!! #309

AdaJass opened this issue Jul 5, 2023 · 2 comments

Comments

@AdaJass
Copy link

AdaJass commented Jul 5, 2023

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

@AdaJass
Copy link
Author

AdaJass commented Jul 5, 2023

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

@sheldoncoates
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants