Esempio n. 1
0
 public function get($url)
 {
     if (\Fuel::$profiling) {
         \Profiler::mark('CMF Cache Start (auto)');
     }
     $this->request = \Request::active();
     $this->path = APPPATH . 'cache/pages/' . \CMF\Cache::uriCacheKey($url) . '.cache';
     if (file_exists($this->path)) {
         $contents = unserialize(file_get_contents($this->path));
         // Check the files first
         $cache_modified = filemtime($this->path);
         foreach ($contents['files'] as $file) {
             $file = PROJECTROOT . $file;
             if (!file_exists($file) || filemtime($file) > $cache_modified) {
                 $this->startListeners();
                 return false;
             }
         }
         // Now check the last modified / record counts from the DB
         if (!empty($contents['sql'])) {
             $result = \DB::query($contents['sql'])->execute()->as_array();
             $result = $result[0];
             if ($result['count'] !== $contents['count'] || strtotime($result['updated_at']) > $contents['updated_at']) {
                 $this->startListeners();
                 return false;
             }
         }
         // See if the cache defines a content type
         if (isset($contents['content-type'])) {
             $this->content_type = $contents['content-type'];
         }
         // We are home and dry - the cache is completely valid.
         // Replicate any logs that were made in the original request
         \CMF\Log::addMultiple($contents['logs_made']);
         // Ok, now we can serve the cache, finally!!
         // We process the cached content to find and replace any areas that shouldn't be cached
         return \CMF\Cache::addNoCacheAreas($contents['nocache'], $contents['content'], array('template' => @$contents['template'], 'module' => @$contents['module']));
     }
     // If we've arrived here, we need to start listening for queries and assets
     $this->startListeners();
     return false;
 }