@deron
To set the Cache-Control HTTP header in OctoberCMS, you can use the beforeSend
event in a middleware. Here is an example of how to do it:
- Create a new middleware class by running the following command in your terminal:
php artisan create:middleware CacheControlMiddleware
- Open the created middleware class (plugins/your-plugin/default/middleware/CacheControlMiddleware.php) and add the following code:
header('Cache-Control', 'public, max-age=3600');
return $response;
}
}
- Register the middleware class in your plugin's Plugin.php file (plugins/your-plugin/Plugin.php) by adding the following code to the register() method:
use YourPluginMiddlewareCacheControlMiddleware;
public function register()
{
$this->app['IlluminateContractsHttpKernel']
->pushMiddleware(CacheControlMiddleware::class);
}
- After making these changes, clear the OctoberCMS cache using the php artisan cache:clear command in your terminal.
Now, every response sent by OctoberCMS will include the Cache-Control header with the value public, max-age=3600
. You can modify this value according to your needs.