首页 > mongodb+nodejs怎么做缓存??

mongodb+nodejs怎么做缓存??

类似于朋友圈,当大量用户拉feed时,是不是需要一个缓存来放置最新的数据呢?

应该选择Redis 还是Memcached 呢?

如果选择redis,是不是不能和mongodb放在同一个服务器上?

“if you put MongoDB and Redis on the same box and MongoDB data do not fit in memory, MongoDB will “steal” memory to Redis via the OS paging mechanism. The consequence is a major performance drop for Redis.”

缓存里应该存什么?存所有的原始数据吗??还是只存_id字段之类的??

http://www.infoworld.com/article/2825890/application-development/why-r...
http://stackoverflow.com/questions/11218941/architecture-for-redis-cac...


既然你后端是使用node.js,那么mongoDB作为你的主数据库。
需要缓存的数据的结构比较多比较复杂,使用Redis。
如果比较简单,没有特别的功能,就使用Memcached。
不过我强烈推荐使用Redis。
Redis可以和你的主数据库在同一台服务器上,也可以不同,这个随便你。
至于缓存,当然是你需要缓存什么就缓存什么。你如果只缓存_id,那还不是需要去mongoDB中查询啊。
比如:你朋友圈的朋友都有备注名,你觉得每次根据好友关系去查备注名,那你可以把这部分数据放到Redis中,就避免去主数据库中查。

【热门文章】
【热门文章】