简体   繁体   English

如何在Ruby on Rails中将数据存储在内存中

[英]How to store data in memory in Ruby on Rails

Our app has to log users' actions pretty frequently (10~15s), and it can be pretty heavy IO. 我们的应用程序必须经常记录用户的操作(10~15s),并且IO可能非常繁重。 Therefore we do not want to store the data into the database every time when user updates something, and we want to store everything in memory (eg an array), and then store them into the database when the memory reaches certain size.The log of different users should go to the same memory, for our purpose. 因此,我们不希望每次用户更新时都将数据存储到数据库中,并且我们希望将所有内容存储在内存中(例如数组),然后在内存达到一定大小时将它们存储到数据库中。为了我们的目的,不同的用户应该去同一个记忆。

We have done some cache on the client side already, but we want to optimize it further on the server. 我们已经在客户端做了一些缓存,但我们希望在服务器上进一步优化它。

Is there any good way in ROR to do it? ROR有什么好办法吗?

Thanks! 谢谢!

This is a common issue. 这是一个常见问题。 If you are interested in caching data structures Redis is lightning fast memory-based data structure server which is commonly used to lighten the load on the disk-based database. 如果您对缓存数据结构感兴趣,Redis是基于闪存的快速内存数据结构服务器,通常用于减轻基于磁盘的数据库的负载。 Here is a recent, as of 2015, article on the subject. 以下是截至2015年的最新文章。 http://www.sitepoint.com/rails-model-caching-redis/ http://www.sitepoint.com/rails-model-caching-redis/

Rails also has native memory-based cache features if you don't want to use Redis or Memcached: http://guides.rubyonrails.org/caching_with_rails.html#activesupport-cache-store 如果您不想使用Redis或Memcached,Rails还具有基于内存的本机缓存功能: http//guides.rubyonrails.org/caching_with_rails.html#activesupport-cache-store

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM