1

I will be working on a large data set that changes slowly so I want to optimize the query result time by using a caching mechanism. For example , if I want to see some metrics about the data from the last 360 days I don't need to query the database again because I can reuse the last query result. Does MongoDB natively support caching or do I have to use another database , for example Redis as mentioned here

EDIT : my question is different from Caching repeating query results in MongoDB because I asked about external caching systems and the response in the late question was specific to working with MongoDB and Tornado

Community
  • 1
  • 1
Nabil
  • 121
  • 1
  • 11
  • Mongodb has not native caching system. You have to use an other system for caching or you have to make a caching system over mongodb by yourself. The best solution is the first choice and the most well-known system for that is Redis. – Moi Syme Mar 20 '17 at 09:46
  • Possible duplicate of [Caching repeating query results in MongoDB](http://stackoverflow.com/questions/14243588/caching-repeating-query-results-in-mongodb) – LuFFy Mar 20 '17 at 10:30
  • @LuFFy I already saw the other question and I think the response was specific to working with MongoDB and Tornado. It did not mention caching systemes that's why I decided to ask this question. – Nabil Mar 20 '17 at 15:00

1 Answers1

0

The author of the Motor (MOngo + TORnado) package gives an example of caching his list of categories here: http://emptysquare.net/blog/refactoring-tornado-code-with-gen-engine/

Basically, he defines a global list of categories and queries the database to fill it in; then, whenever he need the categories in his pages, he checks the list: if it exists, he uses it, if not, he queries again and fills it in. He has it set up to invalidate the list whenever he inserts to the database, but depending on your usage you could create a global timeout variable to keep track of when you need to re-query next. If you're doing something complicated, this could get out of hand, but if it's just a list of the most recent posts or something, I think it would be fine.

LuFFy
  • 8,799
  • 10
  • 41
  • 59