Cache and fetch output by using an Output object

This commit is contained in:
Giuseppe Criscione 2019-04-25 19:38:04 +02:00
parent 3d45a15e25
commit 6ad8ad9d0b

View File

@ -150,8 +150,13 @@ class Formwork
*/
public function run()
{
if ($this->option('cache.enabled') && $data = $this->cache->fetch($this->cacheKey)) {
echo $data;
if ($this->option('cache.enabled') && $output = $this->cache->fetch($this->cacheKey)) {
if ($output instanceof Output) {
$output->sendHeaders();
echo $output->content();
} else {
echo $output;
}
return;
}
@ -170,10 +175,11 @@ class Formwork
$this->site->setCurrentPage($resource);
}
$data = $this->site->currentPage()->render();
$content = $this->site->currentPage()->render();
if ($this->option('cache.enabled') && $this->site->currentPage()->cacheable()) {
$this->cache->save($this->cacheKey, $data);
$output = new Output($content, $this->site->currentPage()->get('response-status'));
$this->cache->save($this->cacheKey, $output);
}
}