View Single Post
Old 12-08-2007, 04:41 PM   #5 (permalink)
Jay
The Contributor
Good Samaritan 
 
Join Date: Dec 2007
Posts: 60
Thanks: 5
Jay is on a distinguished road
Default

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 
unserializefile_get_contents$path ) );
    }
    else
    {
        if( 
$result mysql_query$query ) )
        {
            
$file fopen$path'w+' );
            
fwrite$fileserialize$result ) );
            
fclose$file );

            return 
$result;
        }
        else
        {
            return 
mysql_error();
        }
    }

Jay is offline  
Reply With Quote