tags:

views:

44

answers:

2

I have a page that shows statistics for users, this cannot be cached because each user has different statistics and there are many thus the real time query must be made.

What the way to avoid database server overload when user will click F5's to refresh or to ask different queries in short time intervals ?

+2  A: 

You could store the generated statistics in your database for some time, and just show the old values if the statistics are requested again.

Jens
what do you mean by that ? statistics are stored in the way they are presented to user. I need a way to avoid user from ie. filtering by some word in short period of time. If i will save each result set in database this very table will be the bottleneck..
eugeneK
+2  A: 

I think @Jens A. is halfway there - this is a perfect case for caching, calculate the stats, stick them into the cache with a fixed expiry time and then only calculate them if they're not in the cache. By having the expiry time set to an appropriate value (5 minutes, less?) the stats will still be reasonably up to date and will change (update) at a reasonable without having to be calculated every time if the pages are being refreshed continuously.

Murph
ok, when i make a query i pass few parameters from session and few controls like date and names. I will be creating cached result set with 4 parameters like userID,date1,date2 and name... It's not possible imho.
eugeneK
No, you cache the value with `UserID` as the only parameter; that way, if any user refreshes within the 5-minute period, he'll get the cached stats, and each user will only be able to force a re-calc after the key has expired. Your cache is basically acting as a rate-limiter for user requests.
tzaman