简体   繁体   中英

Array vs Database lookup

I am storing a refresh token in javascript array & same in each user's info table. When user request for data i check the token in array. for matching token i loop the array to check token, if token not found in array i lookup the user's info table for token.

My question is the performance of array vs database lookup: whichis better if users increased in future.

Javascript:

validateToken.forEach(element => {
    if (token == element) {
        retun true;
    }
});

else lookup DB for token

I believe you are using node.js as backend and its connected to some database. Given the design it's generally not a good practice to store tokens in memory. If you are validating a request, then the token should be present in the header.

Also, if you are using JWT then you don't need to store tokens anywhere, you can always verify token to see if it's tampered with. Eitherways you'll have to query the database to check if token information matches with database entry.

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