Answer the question
In order to leave comments, you need to log in
Is it okay to cache data in regular node.js project variables?
For a task list application in which you can assign performers and reviewers, I think in advance how to properly cache the data of all application users, since they will be needed many times when requesting task lists. When we display the list, you can see who created the task, who is the performer, who is the reviewer. The list can contain, for example, 20 tasks, and each task can have 3 subjects. I immediately rejected the idea of getting information about subjects from the database (I use mysql), I looked at REDIS, but I need multi-level storage (since it would be nice to save for each user and the projects in which he participates, his roles in each project, etc. , mb something else in the future), you need to separately cache the array of roles in each project with their privileges. And so I look at REDIS and, due to my superficial acquaintance with it, it seems to me that it will be difficult to store and change multi-level data in it. For some reason, I also don’t like saving and reading data by serializing and parsing JSON. Ideally, the option "mongo-db in ram" or something simpler, but with the same meaning, would be suitable.
While I'm trying to implement it simply by creating a custom storage object. Of course, if the node crashes, then when we restart, we again select all users from the database and upload them to the object, when the information of a user changes, we simply overwrite the information by the cache.users[id] = {...new data... } In this approach, I didn’t notice any critical
minuses
, most likely due to my inexperience, of course
{
name: 'hj1505238475597',
avatar: 'avatar21505238475597',
projectRoles: {
'2': [ 4, 6 ]
}
}
Answer the question
In order to leave comments, you need to log in
The very essence of caching data in variables is normal, but not for such data, or at least not so, we cannot control memory and data volumes, because tasks and users may be, as I understand it, an unknown number, which means our memory is in danger, the base easily cope with a query and a couple of JOINs in it
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question