Skip to content

Commit

Permalink
Merge pull request #5 from yediyuz/cache-tags
Browse files Browse the repository at this point in the history
Add Cache-Tags to Middleware
  • Loading branch information
mertasan authored Dec 23, 2023
2 parents c20c325 + 59921e8 commit 880a8cb
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
6 changes: 0 additions & 6 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,6 +0,0 @@
parameters:
ignoreErrors:
-
message: "#^Class App\\\\Http\\\\Middleware\\\\EncryptCookies not found\\.$#"
count: 1
path: config/cloudflare_cache.php
5 changes: 4 additions & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
includes:
- phpstan-baseline.neon
- vendor/larastan/larastan/extension.neon
- phpstan-baseline.neon

parameters:
level: 8
Expand All @@ -9,3 +9,6 @@ parameters:
- config

tmpDir: build/phpstan

ignoreErrors:
- "#^Class App\\\\Http\\\\Middleware\\\\EncryptCookies not found\\.$#"
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 880a8cb

Please sign in to comment.