Jump to content
  • Advertisement
Sign in to follow this  
MindWipe

[web] Manually caching queries?

This topic is 3715 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey, When I began web programming and using databases I cached most things myself. Then I got the impression that no matter how complex the query the database will cache what it needs itself. No need for you to worry about that. But is that right? So for this one web site I got: - users - posts Each post has a rating. Now I want to know the post count and rating per user(sum of ratings of user's posts). I used to just do this query when I needed it, group by user and sum the rating and count the amount. But now I'm thinking I might as well add postcount and rating to the user table and calculate the postcount when the user posts something or deletes a post and count the user rating when someone rates one of the user's posts? What is smarter to do? Ofcourse leaving everything to the database is nice, but then again having the user's postcount and rating stored in the user row is nice too. /Mindwipe

Share this post


Link to post
Share on other sites
Advertisement
Yes, in general you can leave it to the database engine to come up with performance enhancing strategies, caching being one of them. When in doubt, always profile your database use and use the analysis to further optimize it. In your particular case it might be a good idea to denormalize the architecture slightly, but be sure to find out that it's really a bottleneck and that manually 'caching' is really an improvement. Depending on your database engine, you could choose to employ triggers or calculated fields to automatically keep the count. At least that way you would know that the value is always correct.

Share this post


Link to post
Share on other sites
Ok, thanks. Seems like the db is really quick on doing most tasks, I did some benchmarking of the queries I wanted. So better leave it to the db.

/MindWipe

Share this post


Link to post
Share on other sites
The database may be really fast at counting posts per user, for instance, because it can get that value directly from an index.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!