Forum Moderators: open

Message Too Old, No Replies

Best way to cache database queries for dynamic pages?

         

Parlays

9:22 am on Feb 7, 2008 (gmt 0)

10+ Year Member



I have been trying to learn what the best methods for increasing server performance on pages that use content from an external source such as a database.

The content does change but not often and I am wondering what techniques can be used so that if the content has not changed the page is loaded from a cache or something like that.

Would it be good to draw the information from an XML file and have the system check the last modified time of the XML file? I'm not sure I'm on the right track, any help is appreciated.

Otaku

4:37 pm on Feb 8, 2008 (gmt 0)

10+ Year Member



The fastest way to cache is to save to disk files. Disk IO functions in PHP are very highly optimized.

For example, after constructing a DB query, you can hash that query, and save the result of the query in a temporary file with the hash's name. Then, before running any query, you may first look if the corresponding file already exists, and if it does, read the data from the file instead of the DB - that would be much faster.

You can clear all the cache files when you insert or update data in the DB, and the consequent queries will be run on fresh data.

Parlays

10:47 pm on Feb 13, 2008 (gmt 0)

10+ Year Member



Nice I like that advice, thank you I will definitely try that right now. Much appreciated. Any other techniques you recommend for caching or speeding up queries?