From d748ef1478b4bf8ced12ab88ce24e28f8a9b83f6 Mon Sep 17 00:00:00 2001 From: kenjis Date: Mon, 3 Jul 2023 13:38:35 +0900 Subject: [PATCH] refactor: don't make cahce if $ttl is 0 --- system/Cache/ResponseCache.php | 11 +++++------ system/CodeIgniter.php | 4 +--- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/system/Cache/ResponseCache.php b/system/Cache/ResponseCache.php index 8a3865b3814e..b4c2fe9187fa 100644 --- a/system/Cache/ResponseCache.php +++ b/system/Cache/ResponseCache.php @@ -52,11 +52,6 @@ public function __construct(CacheConfig $config, CacheInterface $cache) $this->cache = $cache; } - public function getTtl(): int - { - return $this->ttl; - } - /** * @return $this */ @@ -90,12 +85,16 @@ public function generateCacheKey($request): string } /** - * Caches the full response from the current request. + * Caches the response. * * @param CLIRequest|IncomingRequest $request */ public function make($request, ResponseInterface $response): bool { + if ($this->ttl === 0) { + return true; + } + $headers = []; foreach ($response->headers() as $header) { diff --git a/system/CodeIgniter.php b/system/CodeIgniter.php index 20d788132677..2ff8da02d456 100644 --- a/system/CodeIgniter.php +++ b/system/CodeIgniter.php @@ -527,9 +527,7 @@ protected function handleRequest(?RouteCollectionInterface $routes, Cache $cache // Cache it without the performance metrics replaced // so that we can have live speed updates along the way. // Must be run after filters to preserve the Response headers. - if ($this->pageCache->getTtl() > 0) { - $this->pageCache->make($this->request, $this->response); - } + $this->pageCache->make($this->request, $this->response); // Update the performance metrics $body = $this->response->getBody();