Click here to Skip to main content
15,886,919 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
I want to store a high computational parameter to prevent its recomputation. But this parameter needs to be updated frequently to maintain consistency, should I use cache or a database or is there any other better solution for this?? I am using a mongodb database though.

What I have tried:

Based on my research, I found that caching is good for use cases where we need to store high computational parameter which is frequently accessed?? But I am confused about the impact of frequent update on this scenario.

I am a beginner in system design and its related concepts, please help me.
Posted
Updated 2-Oct-23 2:29am
v2

1 solution

All a Cache is is memory that is "closer to the processor" - often part of the same chip, and which is faster for the processor to access that having to go outside the CPU to main memory top get the value.
And all frequent updates will do is ensure that the value stays in cache.

If you want to create your own cache within your app, that's fine - just decide where it needs to be used and updated because Javascript code is executed on the client, and for the server to get near it means a round trip across the internet, and the same thing for the reverse - if you store it on the server and the client needs it, that's another round trip.

A database is generally outside the server so storing it there and updating it frequently will generate a lot of traffic, and that could consume a lot of your MongoDB server bandwidth, slowing everybody using it down. And then, if it's used or calculated at the client, you have two round trips involved: client <-> server <-> DB server. More bandwidth, more slowdown.

DB's are for things you need to remember once your app has closed so it can be accessed again when it reopens. Caches are volatile data that is discarded when your app closes (unless your app specifically saves them - maybe to a DB - when it closes).

We can't tell you "use this" - it neds way too much knowledge of your systems and how they anad your app work that we just don't have access to
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900