From 698c33a395a0ffafbc3f491bea2abfaf039860f5 Mon Sep 17 00:00:00 2001 From: Nick Date: Fri, 1 Oct 2021 00:07:58 +0930 Subject: [PATCH] Cache page content hubertusanton/silverstripe-seo#40 --- src/SeoObjectExtension.php | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/SeoObjectExtension.php b/src/SeoObjectExtension.php index edf021e..2842e0d 100644 --- a/src/SeoObjectExtension.php +++ b/src/SeoObjectExtension.php @@ -811,16 +811,22 @@ public function getNumCharsTitle() { */ public function getPageContent() { - $session = []; - if (Controller::has_curr()) { - $session = Controller::curr()->getRequest()->getSession(); - } - $response = Director::test($this->owner->Link(), [], $session); + static $cache = null; + + if ($cache === null) { + $session = []; + if (Controller::has_curr()) { + $session = Controller::curr()->getRequest()->getSession(); + } + $response = Director::test($this->owner->Link(), [], $session); - if (!$response->isError()) { - return $response->getBody(); + if (!$response->isError()) { + $cache = $response->getBody(); + } else { + $cache = ''; + } } - - return ''; + + return $cache; } }