Replies: 2 comments 1 reply
-
@emredipi Can we make the header programable.? |
Beta Was this translation helpful? Give feedback.
1 reply
-
For future readers: you can use middleware to control the headers.
<?php
declare(strict_types=1);
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;
use Yediyuz\CloudflareCache\CloudflarePagesMiddleware;
class SetCacheControlHeader
{
/**
* Handle an incoming request.
*
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
*/
public function handle(Request $request, Closure $next): Response
{
/** @var Response $response */
$response = $next($request);
if ((new CloudflarePagesMiddleware)->shouldCacheResponse($request, $response)) {
$response->headers->set('Cache-Control', 'max-age=0, s-maxage=2592000');
}
return $response;
}
}
Route::middleware([SetCacheControlHeader::class])->group(function () {
//...
}); |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Right now we are forced to use header:
'Cache-Control' => "max-age=$ttl, public"
, sometimes that's not what we want.In my case, I wanted to use different header:
'Cache-Control' => 'max-age=0, s-maxage=600'
.Proposal
We can add a third parameter
headers
incache()
with same default type and value as$tags
. Ifheaders
is not null then we use that else use the default.Beta Was this translation helpful? Give feedback.
All reactions