How “View Count” is best implemented?

前端 未结 6 678
梦谈多话
梦谈多话 2021-01-30 18:07

On any website, such as on StackOverflow, each question has a view count, and user reading a question but has previous read it won\'t count twice.

I have some ideas abou

6条回答
  •  误落风尘
    2021-01-30 18:47

    Short answer: It depends!

    • It really depends on how accurate you need your view count to be, is it acceptable that one person might be registered two or three times?
    • It depends on what you're gonna use the data for. If you want do other neat things with the data (statistics, recent view list and so on) you might want to consider storing all the individual views in a database. This might result in a huge table so you have to thing this through before implementing it.

    I've previously used cookies combined with an in-memory database to store the individuals view's (for obvious reasons I stored the actual view count in a database table persisted to disk). I could do this because the statistics didn't mean anything.

提交回复
热议问题