1

所以我试图用默认的 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 Catchable 致命错误:传递给 Symfony\Component\HttpKernel\HttpCache\HttpCache::__construct() 的参数 2 必须是 Symfony\Component\HttpKernel\HttpCache\StoreInterface 的实例,未给出,在 /php/api 中调用第 11 行的 /current/web/app.php 并在第 78 行的 /php/api/current/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpCache/HttpCache.php 中定义

鉴于 HttpCache 类构造函数,这非常有意义。

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

4

1 回答 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);
于 2017-04-12T17:32:56.250 回答