How to stop MongoDB from reloading data every time I refresh a page?

六眼飞鱼酱① 提交于 2021-02-11 18:21:24

问题


Basically I am practicing NodeJs/MongoDB by making a simple blog app. I am using the .find() method to final all the saved blogs on the db, and then running it through a loop to post it on the main page. That method is called every time the page is refreshed, so

how do I stop it from being called to avoid automatic reposts?

exports.getBlogEntries = function() {

    Entry.find(function(err, entries) {

        if (!err){ 
            for(i = 1; i < entries.length; i++ ) {
                list.push(entries[i]);
            }
        }
    });
    return list;
};

回答1:


As noted above:

I would suggest using LRU cache (node-lru-cache seems to be nice implementation) so you won't have to worry about overflow. Basically the pattern would be: check if blog entries exist in cache and return then if they do; otherwise read them from MongoDB, insert to cache and return to a customer. I hope that will give you some directions.



来源:https://stackoverflow.com/questions/21353273/how-to-stop-mongodb-from-reloading-data-every-time-i-refresh-a-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!