Question: caching query results (memory, redis, etc.)
Quick question: how do you guys cache your mongoose query results? I know mongodb is supposed to be fast et al, but some heavy queries (like aggregate) in some use-cases benefit a lot from in-memory or redis result caching. There are some existing npm packages to do that, but they are all failing to do the job correctly. And they are all obscure 12 stars, not updated since 2014, monkey-patching codebase.
Caching is such an important matter in software engineering, that I'm wondering why there is no "official" way to do that in mongoose.
It's definitely something to add for the future, but not something we have good support for just yet. Has never really been a problem in my experience because we usually don't run heavy aggregates transactionally. If there's a heavy aggregate, I'd just compute it once a day and store the results in a collection.
Hi @vkarpov15 , Was there any update on this? Did I miss anything here? Please let me know if there is any way out to provide the caching with Aggregate queries. Sorry, If I missed any official update on this
@desaijay315 no official update on this yet. You would have to use a plugin or write your own caching.
I would recommend avoiding using aggregations for performance-sensitive code. Try to leverage demoralization to avoid expensive aggregations.
Thank you so much @vkarpov15 for your prompt response!
Currently, I am using Redis in a manual fashion. I liked your suggestion on demoralization by the way. Thanks a lot!