Giter Site home page Giter Site logo

Comments (2)

AdaJass avatar AdaJass commented on June 3, 2024
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

from node-cache.

sheldoncoates avatar sheldoncoates commented on June 3, 2024

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

from node-cache.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.