In memory storage on nodejs server

[亡魂溺海] 提交于 2019-12-06 06:50:19

问题


There seem to be quite a few promising packages with no clear suggestions on which is the fastest,scalable and which is more memory efficient.

  1. npm install memoizee
  2. npm install memcached
  3. lru-cache
  4. npm install memory-cache
  5. npm install node-cache

Any reliable sources of information/personal experience with these would help.
So the basic usage is for simple key:value store.
Just need to know if the underlying architecture of these different stores is similar/different and if different then which would be scalable.

[Also which of these is used by express-session to implement the MemoryStore.]


回答1:


The dependencies for express-session are right on Github in its package.json. I don't see any of your listed storage mechanisms.

Then, if you look at the code for the MemoryStore object here, you can see that it's just using a Javascript object to store a list of sessions indexed by sessionId.




回答2:


"Which one is better" depends on your requirements such as traffic volume, how much you want to store in-memory cache etc.

When you select an in-memory store, keep in mind node.js is single-threaded and for-loops are blocking codes. If you look at the source for most of these packages such as node-cache, they all have for-loops, iterating through all your cached items for TTL check. So if you store 10000 objects, your app is going to be blocked until 10k iteration is completed. So beware of your choice.



来源:https://stackoverflow.com/questions/34304740/in-memory-storage-on-nodejs-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!