[英]FOSHttpCache with Symfony reverse proxy
因此,我嘗試使用默認的Symfony HttpCache配置FOSHttpCacheBundle(最新版本^ 2.0) 。
根據文檔,這是我的AppCache.php的內容:
<?php
use FOS\HttpCache\SymfonyCache\CacheInvalidation;
use FOS\HttpCache\SymfonyCache\EventDispatchingHttpCache;
use FOS\HttpCache\SymfonyCache\DebugListener;
use FOS\HttpCache\SymfonyCache\CustomTtlListener;
use FOS\HttpCache\SymfonyCache\PurgeListener;
use FOS\HttpCache\SymfonyCache\RefreshListener;
use FOS\HttpCache\SymfonyCache\UserContextListener;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\HttpCache\HttpCache;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\HttpCache\StoreInterface;
use Symfony\Component\HttpKernel\HttpCache\SurrogateInterface;
class AppCache extends HttpCache implements CacheInvalidation
{
use EventDispatchingHttpCache;
/**
* Overwrite constructor to register event listeners for FOSHttpCache.
*/
public function __construct(
HttpKernelInterface $kernel,
StoreInterface $store,
SurrogateInterface $surrogate = null,
array $options = []
) {
parent::__construct($kernel, $store, $surrogate, $options);
$this->addSubscriber(new CustomTtlListener());
$this->addSubscriber(new PurgeListener());
$this->addSubscriber(new RefreshListener());
$this->addSubscriber(new UserContextListener());
if (isset($options['debug']) && $options['debug']) {
$this->addSubscriber(new DebugListener());
}
}
/**
* Made public to allow event listeners to do refresh operations.
*
* {@inheritDoc}
*/
public function fetch(Request $request, $catch = false)
{
return parent::fetch($request, $catch);
}
}
現在根據Symfony的文檔 ,從而使高速緩存代理只是一個設定app.php文件如下的物質(取消注釋最后一行):
$kernel = new AppKernel('prod', false);
$kernel->loadClassCache();
$kernel = new AppCache($kernel);
這給了我一個不錯的選擇:
PHP消息:PHP捕獲的致命錯誤:傳遞給Symfony的\\元器件參數2 \\ HttpKernel \\ HttpCache \\ HttpCache :: __構建體()必須的Symfony \\組件的實例\\ HttpKernel \\ HttpCache \\ StoreInterface,沒有給出,稱為在/ PHP / API /current/web/app.php上線11和上線78在/php/api/current/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpCache/HttpCache.php定義
這使得給予HttpCache類的構造非常有意義。
所以問題是,是不是最新的文檔,還是僅僅是我遺漏了一些明顯的東西?
use Symfony\Component\HttpKernel\HttpCache\Store;
$kernel = new AppKernel('dev', true);
$kernel->loadClassCache();
$store = new Store('app/cache');
$kernel = new AppCache($kernel, $store);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.