示例#1
0
 /**
  * Builds pages.
  *
  * @internal
  */
 protected function buildPages()
 {
     $this->sort = array();
     /** @var Config $config */
     $config = $this->grav['config'];
     /** @var UniformResourceLocator $locator */
     $locator = $this->grav['locator'];
     $pagesDir = $locator->findResource('page://');
     if ($config->get('system.cache.enabled')) {
         /** @var Cache $cache */
         $cache = $this->grav['cache'];
         /** @var Taxonomy $taxonomy */
         $taxonomy = $this->grav['taxonomy'];
         // how should we check for last modified? Default is by file
         switch (strtolower($config->get('system.cache.check.method', 'file'))) {
             case 'none':
             case 'off':
                 $last_modified = 0;
                 break;
             case 'folder':
                 $last_modified = Folder::lastModifiedFolder($pagesDir);
                 break;
             default:
                 $last_modified = Folder::lastModifiedFile($pagesDir);
         }
         $page_cache_id = md5(USER_DIR . $last_modified . $config->checksum());
         list($this->instances, $this->routes, $this->children, $taxonomy_map, $this->sort) = $cache->fetch($page_cache_id);
         if (!$this->instances) {
             $this->grav['debugger']->addMessage('Page cache missed, rebuilding pages..');
             $this->recurse($pagesDir);
             $this->buildRoutes();
             // save pages, routes, taxonomy, and sort to cache
             $cache->save($page_cache_id, array($this->instances, $this->routes, $this->children, $taxonomy->taxonomy(), $this->sort));
         } else {
             // If pages was found in cache, set the taxonomy
             $this->grav['debugger']->addMessage('Page cache hit.');
             $taxonomy->taxonomy($taxonomy_map);
         }
     } else {
         $this->recurse($pagesDir);
         $this->buildRoutes();
     }
 }
示例#2
0
 /**
  * Builds pages.
  *
  * @internal
  */
 protected function buildPages()
 {
     $this->sort = array();
     /** @var Config $config */
     $config = $this->grav['config'];
     if ($config->get('system.cache.enabled')) {
         /** @var Cache $cache */
         $cache = $this->grav['cache'];
         /** @var Taxonomy $taxonomy */
         $taxonomy = $this->grav['taxonomy'];
         $last_modified = 0;
         // how should we check for last modified? Default is by file
         switch (strtolower($config->get('system.cache.check.method', 'file'))) {
             case 'none':
             case 'off':
                 $last_modified = 0;
                 break;
             case 'folder':
                 $last_modified = Folder::lastModifiedFolder(PAGES_DIR);
                 break;
             default:
                 $last_modified = Folder::lastModifiedFile(PAGES_DIR);
         }
         $page_cache_id = md5(USER_DIR . $last_modified);
         list($this->instances, $this->routes, $this->children, $taxonomy_map, $this->sort) = $cache->fetch($page_cache_id);
         if (!$this->instances) {
             $this->recurse();
             $this->buildRoutes();
             // save pages, routes, taxonomy, and sort to cache
             $cache->save($page_cache_id, array($this->instances, $this->routes, $this->children, $taxonomy->taxonomy(), $this->sort));
         } else {
             // If pages was found in cache, set the taxonomy
             $taxonomy->taxonomy($taxonomy_map);
         }
     } else {
         $this->recurse();
         $this->buildRoutes();
     }
 }