4

iOS アプリ用に Symfony2 で API を作成しました。アプリは、header-parameter を使用して GET リクエストを送信しますif-modified-since

"If-Modified-Since" = "Thu, 07 Nov 2013 11:50:52 GMT";

コントローラーでパラメーターをチェックし、日付が新しい場合はデータを返します。しかし、Symfony2 では、クラスの本番環境で Parameter が削除されます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 はリクエストのこの応答のキャッシュ エントリを見つけられず、キャッシュするコンテンツがあることを確認するためにこのパラメータを削除しているように見えますが、エントリは見つかりません。また、多くのリロードの後。

コントローラーでこのパラメーターが必要です。現時点では、アプリがパラメーターを変更したり、日付値を含む他のパラメーターを送信したりする可能性はありません。

いくつかの構成または何かを行う必要がありますか?

誰かが私を助けてくれれば本当に感謝しています。

4

1 に答える 1

1

app/AppCache.php代わりに使用しているprod envにあるようです。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 キャッシュについて読む必要があります

于 2014-06-10T06:19:56.720 に答える