How can I cache a dynamic page to a flat file in PHP?
<p>I am trying to roll a caching system to reduce the load on the database.</p>

<p>I want to be able to compare timestamps of the last updated time the flat file was updated 
to make sure it's not too long ago that the file was last updated.</p>

<p>Here's the code:
    

<pre><code>$cache_file = $_GET[ 'page_id' ] . '.html';

function cache() {

    // Here i want to get the timestamp of the file that was previously cached, 
    // if it exists.
    // If the file doesn't exist, create it.
    // If it does exist, check last modified time, if it's too long ago, then overwrite
    // the file.


    $ob = ob_get_contents();

    file_put_contents( $cache_file, $ob );

}

function loadFromCache( $page_id ) {
    $file_name = $page_id . '.html';
    if( ! file_exists( $file_name  ) ) {
         return false;
    }
    readfile( $file_name );
    return true;
}
</code></pre>

<p>Thank you.</p>
