There are many potential solutions. The first and most obvious is the use of session middleware for express delivery. Most web frameworks should have some kind of session solution.
https://github.com/expressjs/session
The next option would be to use a caching utility, for example, what Vsevolod suggested. It does almost the same thing as a session, except that the data must be bound to the user / session, then you will have to store some kind of identifier in the session and use it to retrieve from the cache. I think this is a little redundant if this is your use case.
There are also utilities that will expand your mid-level sessions and store objects in a session in a database or in other types of data stores so that session information is not lost even after a server restart. You still get the storage speed in memory, but maintain the database if memory in memory is flushed.
Another option is to use Redis . You still have to serialize / deserialize your objects, but Redis is a data store in memory and can write and read very quickly.
source share