12-08-2007, 03:41 PM
|
#5 (permalink)
|
|
The Contributor
Join Date: Dec 2007
Posts: 60
Thanks: 5
|
No sorry I don't, I have never read a tutorial about caching
What you could do is use MD5() on the query text (ie: "SELECT * FROM"), store that as a filename in a directory like ./cache/sql/<md5 result>.txt, then check the filetime to see how old the cache is
PHP Code:
function mysql_cache_query( $query ) { $path = './cache/sql/'. md5( $query ) .'.txt';
if( file_exists( $path ) && filemtime( $path ) + (60 * 10) <= time() ) { return unserialize( file_get_contents( $path ) ); } else { if( $result = mysql_query( $query ) ) { $file = fopen( $path, 'w+' ); fwrite( $file, serialize( $result ) ); fclose( $file );
return $result; } else { return mysql_error(); } } }
|
|
|
|