title: PHP Simple HTML DOM Parser caching multiple pages
body: <p>I am using PHP Simple HTML DOM Parser and using <strong>$html->load_file</strong></p>
  
  <pre><code>include('simple_html_dom.php');
  $html = new simple_html_dom();
  $html-&gt;load_file('https://www.google.com/finance?q=goog');
  </code></pre>
  
  <p>the link below demonstrates a method to force caching of the content.  I need to retrieve pages where the content changes depending on the last part of the url.  Is it possible to modify the code below to force caching, for example, if I retrieve the following pages:</p>
  
  <p>google.com/finance?q=goog</p>
  
  <p>google.com/finance?q=wwwfx</p>
  
  <p>google.com/finance?q=vigrx</p>
  
  <p>Can I cache each one of those pages until the end of the session because I will need the page content repeatedly.</p>
  
  <p><a href="https://stackoverflow.com/questions/6039230/caching-php-simple-html-dom-parser?rq=1">Caching PHP Simple HTML DOM Parser</a></p>
  
  <pre><code>function cache_get_contents($url, $offset = 600, $override = false) {
      $file = '/tmp/file_cache_' . md5($url);
      if (!$override &amp;&amp; file_exists($file) &amp;&amp; filemtime($file) &gt; time() - $offset)
          return file_get_contents($file);
  
      $contents = file_get_contents($url);
      if ($contents === false)
          return false;
  
      file_put_contents($file, $contents);
      return $contents;
  }
  </code></pre>