首页 文章

使用Symfony反向代理的FOSHttpCache

提问于
浏览
0

所以我正在尝试使用默认的Symfony HttpCache配置FOSHttpCacheBundle (latest release ^2.0) .

以下是根据the docs的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 docs,启用缓存代理只需将app.php文件设置为如下(取消注释最后一行):

$kernel = new AppKernel('prod', false);
$kernel->loadClassCache();
$kernel = new AppCache($kernel);

这给了我一个很好的:

PHP消息:PHP Catchable致命错误:参数2传递给Symfony \ Component \ HttpKernel \ HttpCache \ HttpCache :: __ construct()必须是Symfony \ Component \ HttpKernel \ HttpCache \ StoreInterface的实例,没有给出,在/ php /中调用第11行的api / current / web / app.php,在第78行的/php/api/current/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpCache/HttpCache.php中定义

鉴于HttpCache类构造函数,这是完全合理的 .

所以问题是,它是不是最新的文档,还是只是我遗漏了一些非常明显的东西?

1 回答

  • 2
    use Symfony\Component\HttpKernel\HttpCache\Store;
    
    $kernel = new AppKernel('dev', true);
    $kernel->loadClassCache();
    $store = new Store('app/cache');
    $kernel = new AppCache($kernel, $store);
    

相关问题