1

I am trying to make my own blogging system using node.js, express.js with jade and mongodb (hosted on mongolab.com). I want to have on one page list of all posts stored in database. I have worries about page load speed after I add more posts cause I am contacting mongodb each time page refreshes.

My questions are: Is it ok to get data from database each time page refreshes? Or how can I store these data cached somewhere? Or is there a quicker way because these data are not often changed?

2
  • These answers, especially to question 1, depend a lot on the requirements of your webpage/app. The big one being, How often is the page going to be refreshed? If this is a site with 100 concurrent users, caching would be less important than if there are 10000. Are there speeds requirements for page load time? Commented Feb 24, 2016 at 19:19
  • MongoDB does in-memory caching of the most recently requested documents by itself. But when you have a high latency to the database, caching on node.js might save you some ms of pageload latency. Commented Feb 24, 2016 at 20:01

1 Answer 1

1

Regarding query caching on MongoDB, the official documentation says:

MongoDB keeps most recently used data in RAM. If you have created indexes for your queries and your working data set fits in RAM, MongoDB serves all queries from memory.

MongoDB does not cache the query results in order to return the cached results for identical queries.

So, depending on your workload and your hardware resources, you may have a high hit ratio for some queries as a consequence of the first sentence above.

However, consider having a cache layer in front of your site, like a CDN or even some basic caching with Nginx or Varnish. In my opinion, this would be the right solution for you, instead of relying only on the database.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.