2 years agoby Bhagyaraj Aj
Hi, I'm doing a blog like posting their status. And i had done like,comment,share. But now i have to do no. of views count for how many of users viewed their post.Please,help me over the concept of the no. of views functionality.
You need to use Redis where you can save everytime any page is visited by user. Of course you can also use database to save but as project become big, that's not the ideal case to do so.
With redis you can obviously don't want to increase view count every time a page is visited by any user, in that case if user refreshes page 100 times then view count increases to 100 in just a seconds.
For that what you can do, just check when a user has visited a page and put that in a session or cookie which lasts for only 30 sec or 1 min or whatever time you want. In this way even if user refreshes page many times count does't increase, view count only increase for each unique user for a single minute.
So if I visit your page then yes count increases by 1 but if I visit same page after 1 minute then only count further increases otherwise not.
Hope this help you.