laravel page-cache 的整站静态页面缓存

https://www.lmonkey.com/t/o6Eobv7Bl

https://blog.csdn.net/weixin_30311521/article/details/117989930

 

<?php
namespace App\Http\Middleware;

use Silber\PageCache\Cache;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Silber\PageCache\Middleware\CacheResponse as BaseCacheResponse;

class CacheResponse extends BaseCacheResponse
{
    public function __construct(Cache $cache)
    {
        parent::__construct($cache);

        $cache_dir = request()->getHost();

        $this->cache->setCachePath("page-cache/{$cache_dir}");

    }
    protected function shouldCache(Request $request, Response $response)
    {
        if ($request->getQueryString()) {
            return false;
        }
        return parent::shouldCache($request, $response);
    }
}

  

 

posted @ 2022-08-15 14:41  星云惊蛰  阅读(113)  评论(0)    收藏  举报