Skip to content

Commit

Permalink
refactor: don't make cahce if $ttl is 0
Browse files Browse the repository at this point in the history
  • Loading branch information
kenjis committed Jul 3, 2023
1 parent 80465c6 commit d748ef1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
11 changes: 5 additions & 6 deletions system/Cache/ResponseCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,6 @@ public function __construct(CacheConfig $config, CacheInterface $cache)
$this->cache = $cache;
}

public function getTtl(): int
{
return $this->ttl;
}

/**
* @return $this
*/
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 1 addition & 3 deletions system/CodeIgniter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit d748ef1

Please sign in to comment.