How to the view count of a question in momery?
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
4:43 UTC
Read the original article
Hit count: 461
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.
When a user visited 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 them in the database, because the records will be huge. So I want to keep them in the memory, and persistent the number to database every 10 minutes.
I have searched about "cache" of rails, but I haven't found an example. I need an simple sample of how to do this, thanks for help~
© Stack Overflow or respective owner