How to the view count of a question in memory?
Posted
by Freewind
on Stack Overflow
See other posts from Stack Overflow
or by Freewind
Published on 2010-06-18T04:39:55Z
Indexed on
2010/06/18
5:03 UTC
Read the original article
Hit count: 410
ruby-on-rails
|cache
My website is like stackoverflow, there are many questions. I want to record how many times a question has been visited. I have a column called "view_count" in the question table to save it.
If a user visits a question many times, the view_count should be increased only 1. So I have to record which user has visited which question, and I think it is too much expensive to save this information in the database because the records will be huge. So, I would like to keep the information in memory and only persist the number to the database every 10 minutes.
I have searched about "cache" in Rails, but I haven't found an example. I would like a simple sample of how to do this, thanks for help~
© Stack Overflow or respective owner