Symfony2 删除了生产环境中的“if-modified-since”参数


Symfony2 delete the "if-modified-since" parameter on production

我用Symfony2为iOS应用程序做了一个API。应用发送带有标头参数的 GET 请求if-modified-since

"if-modified-since" = "星期四, 07 Nov 2013 11:50:52 GMT";

在控制器中,我检查参数并在日期较新时返回数据。但是在 Symfony2 中,参数将在生产环境中的类Symfony'Component'HttpKernel'HttpCache'HttpCache.php中删除。这是类中的函数。

/**
 * Forwards the Request to the backend and determines whether the response should be stored.
 *
 * This methods is triggered when the cache missed or a reload is required.
 *
 * @param Request $request A Request instance
 * @param Boolean $catch   whether to process exceptions
 *
 * @return Response A Response instance
 */
protected function fetch(Request $request, $catch = false)
{
    $subRequest = clone $request;
    // send no head requests because we want content
    $subRequest->setMethod('GET');
    // avoid that the backend sends no content
    $subRequest->headers->remove('if_modified_since');
    $subRequest->headers->remove('if_none_match');
    $response = $this->forward($subRequest, $catch);
    if ($this->isPrivateRequest($request) && !$response->headers->hasCacheControlDirective('public')) {
        $response->setPrivate(true);
    } elseif ($this->options['default_ttl'] > 0 && null === $response->getTtl() && !$response->headers->getCacheControlDirective('must-revalidate')) {
        $response->setTtl($this->options['default_ttl']);
    }
    if ($response->isCacheable()) {
        $this->store($request, $response);
    }
    return $response;
}

所以看起来Symfony没有找到请求响应的缓存条目并删除此参数以确保会有内容要缓存,但他从未找到条目。也经过多次重新加载。

我在控制器中需要此参数,目前应用程序无法更改参数或发送带有日期值的其他参数。

我必须执行一些配置或其他操作吗?

如果有人能帮助我,我将不胜感激。

似乎在您的产品环境中,您使用的是app/AppCache.php而不是app/AppKernel.php因此,简而言之,如果您想自己处理它,请切换回app/AppKernel.php web/app.php

require_once __DIR__.'/../app/AppKernel.php';
//require_once __DIR__.'/../app/AppCache.php';
$kernel = new AppKernel('prod', false);
$kernel->loadClassCache();
//$kernel = new AppCache($kernel);

在细节上,你应该阅读关于Symfony http缓存的信息