1

I am trying to make a method which would reduce sql requests to speed things up a little bit. My idea was:

  1. Make 1 request from the mysql-db
  2. place data into LocalStorage (json)
  3. If there is something in the LocalStorage, work from there instead of making a new db request
  4. When serving values from LocalStorage add +1 in the LS "view" column
  5. When "view" reached a certain number, make a new sql query refreshing the current LocalS and UPDATE the mysql db with the view number.

The problem is that somebody could overwrite the current view and it would then make false viewcount.

I was thinking about making a little token so it updates everytime when the viewcount changes, however it could be seen on javascript side.

Should I just make queries everytime when a page is loaded (Wouldn't it slow the site down?) or should I use a db like redis? I expect about ~1000s of users or more.

Thank you very much in advance, all ideas are highly appreciated.

razz
  • 11
  • 1
  • Why would you even want to count a page-refresh by the same user as a new view? – Philipp Jul 13 '14 at 14:24
  • use both, things which do not need to be in sync with db all the time, use it in localstorage or sessionstorage(preferable) and else use db.. do not load the entire page, make ajax requests for small changes. – nsthethunderbolt Jul 13 '14 at 14:31
  • If you need to store sensitive information that cannot be tampered with you'll have to use server-side storage. Do you expect 1000 simultaneous connections (which is an extremely high load) or 1000 registered users (which is basically a low traffic site)? – Álvaro González Jul 13 '14 at 14:40
  • @Philipp It is a small ad-system which needs to count impressions. Thank you guys, 1000 registered users can be up to 10k (or more) in the future – razz Jul 13 '14 at 15:19

1 Answers1

0

You may look into caching:

Caching with php file

The most popular way is to use Memcached for caching. Another option is Redis.

Community
  • 1
  • 1
Chris Lam
  • 3,526
  • 13
  • 10