简体   繁体   中英

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. 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?

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. Here is a recent, as of 2015, article on the subject. 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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