diff --git a/code/dispatcher/behavior/cacheable.php b/code/dispatcher/behavior/cacheable.php index 4ff0804d..952b5b25 100644 --- a/code/dispatcher/behavior/cacheable.php +++ b/code/dispatcher/behavior/cacheable.php @@ -184,10 +184,17 @@ protected function _actionCache(KDispatcherContextInterface $context) $response->setDate(new DateTime('now')); $response->setLastModified($response->getDate()); - //If the cache exists and it has not been modified do not reset the Last-Modified date + $time = null; + if($start = $response->getRequest()->getTime()) { + $time = (microtime(true) - $start) * 1000; + } + + //If the cache exists and it has not been modified do not reset the Last-Modified date and timing if($this->loadCache() && $this->isIdentical()) { $cache = $this->loadCache(); + + //Do not reset LastModified $response->setLastModified(new DateTime($cache['headers']['Last-Modified'])); } @@ -201,6 +208,7 @@ protected function _actionCache(KDispatcherContextInterface $context) 'headers' => $response->headers->toArray(), 'content' => (string) $response->getContent(), 'language' => $this->getRoute()->getPage()->language, + 'timing' => (int) $time ); $result = $this->storeCache($data); diff --git a/code/http/cache.php b/code/http/cache.php index 34b54b25..c8c8e3af 100644 --- a/code/http/cache.php +++ b/code/http/cache.php @@ -64,6 +64,8 @@ public function send(KHttpRequestInterface $request) //Revalidate the cache if(!$valid) { + $start = microtime(true); + $response = parent::send($request); if($cache && ($response->isError() || $response->isNotModified())) @@ -82,7 +84,8 @@ public function send(KHttpRequestInterface $request) 'status' => $response->getStatusCode(), 'format' => $response->getFormat(), 'headers' => $response->getHeaders()->toArray(), - 'content' => $response->getContent() + 'content' => $response->getContent(), + 'timing' => (int) ((microtime(true) - $start) * 1000), ]); } }