问题
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