Skip to content

Commit

Permalink
Adds cache tags to middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
mertasan committed Dec 23, 2023
1 parent a642120 commit 59921e8
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/CloudflarePagesMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,21 @@ public function handle(Request $request, Closure $next): Response
if ($this->shouldCacheResponse($request, $response)) {
$response->headers->add(['Cache-Control' => 'max-age=600, public']);
$response->headers->remove('set-cookie');

if ($this->hasCacheTags($request)) {
$tags = implode(',', $this->getCacheTags($request));
$response->headers->add(['Cache-Tags' => $tags]);
}
}

return $response;
}

protected function hasCacheTags(Request $request): bool
{
return $request->attributes->has(CloudflareCache::TAGS_ATTR);
}

/**
* @return array<int, string>
*/
Expand Down

0 comments on commit 59921e8

Please sign in to comment.