/** * Renders the HTML for the page or fetches it from the cache * * @param Page $page * @param boolean $headers * @return string */ public function render(Page $page, $data = array(), $headers = true) { // register the currently rendered page $this->page = $page; // send all headers for the page if ($headers) { $page->headers(); } // cache the result if possible if ($this->options['cache'] and $page->isCachable()) { // try to read the cache by cid (cache id) $cacheId = $page->cacheId(); // check for modified content within the content folder // and auto-expire the page cache in such a case if ($this->options['cache.autoupdate'] and $this->cache()->exists($cacheId)) { // get the creation date of the cache file $created = $this->cache()->created($cacheId); // make sure to kill the cache if the site has been modified if ($this->site->wasModifiedAfter($created)) { $this->cache()->remove($cacheId); } } // try to fetch the template from cache $template = $this->cache()->get($cacheId); // fetch fresh content if the cache is empty if (empty($template)) { $template = $this->template($page, $data); // store the result for the next round $this->cache()->set($cacheId, $template); } return $template; } // return a fresh template return $this->template($page, $data); }