1. Go to this page and download the library: Download haxibiao/page-cache library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
haxibiao / page-cache example snippets
Silber\PageCache\LaravelServiceProvider::class,
protected $middlewareGroups = [
'web' => [
\Silber\PageCache\Middleware\CacheResponse::class,
/* ... keep the existing middleware here */
],
];
protected $routeMiddleware = [
'page-cache' => \Silber\PageCache\Middleware\CacheResponse::class,
/* ... keep the existing mappings here */
];
namespace App\Http\Middleware;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Silber\PageCache\Middleware\CacheResponse as BaseCacheResponse;
class CacheResponse extends BaseCacheResponse
{
protected function shouldCache(Request $request, Response $response)
{
// In this example, we don't ever want to cache pages if the
// URL contains a query string. So we first check for it,
// then defer back up to the parent's default checks.
if ($request->getQueryString()) {
return false;
}
return parent::shouldCache($request, $response);
}
}