Q
Q
quex2014-07-06 11:07:02
MongoDB
quex, 2014-07-06 11:07:02

Does it make sense to cache "locally" the results of mongodb queries in NodeJS?

The site has entities such as localization, a list of supported languages, menu items, etc., which are stored in mongo. Their volume is correspondingly small.
These entities are primarily used when rendering the page.
Does it make sense to get this data once when starting the web server and write it to a variable? One of the downsides here is immediately obvious - at least you have to bother with your bikes to keep the "cache" up to date.
As far as I know, monge has good support for query caching out of the box. But I don’t know all the intricacies of the functioning of the mechanism, so the very fact that these “extra” requests are executed every time the page is loaded (which are from 15-20 per second) is a little scary.
As far as I know, monga caches query results in memory. Then it turns out that the profit will be only in avoiding calls to a number of internal mongi methods that return the cache from memory. Is it so?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Vlasenko, 2014-07-06
@quex

If there is a desire to write your own cache, then you should take a step back and think again about the architecture.
Answer: It is definitely not worth caching results from Mongo locally.
And now in more detail:
In Monge, the cache is quite trickier than saving the last result. ( docs.mongodb.org/manual/faq/fundamentals/#does-mon... ) Moga can store only indexes in RAM and the "caching" performance gain occurs only when all the fields required by the query are included in the index, and the index is in its own queue in the RAM after the previous request to the same collection.
Solution options:
1) If the data changes often (minutes) - then as a variant of the mong, respectively, without "own" caching. But if the data (localization strings, menus) falls on the key / value structure, then it is advisable to use something more intended for "fast" reading like redis or with a multi-node architecture, then etcd
2) If the data changes rarely (days), then ordinary files with localizations (loading at the start of the app) will be the best option =)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question