I made a API with Symfony2 for a iOS-App. The App send a GET request with the header-parameter if-modified-since
"If-Modified-Since" = "Thu, 07 Nov 2013 11:50:52 GMT";
In the controller I check the parameter and return the data if the date is newer. But in Symfony2 the Parameter would be deleted on the production environment in the class Symfony\Component\HttpKernel\HttpCache\HttpCache.php
. Here is the function in the class.
/**
* 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;
}
So it looks like Symfony doesn't find a cache entry for this response of the request and delete this parameter to be sure, that there will be content to cache, but he never find a entry. Also after many reloads.
I need this parameter in the controller, there is at the moment no chance that the app can change the parameter or send an other parameter with the date value.
Do I have to do some configurations or something else?
I would really appreciate if someone could help me.
It seems in your prod env you are using app/AppCache.php instead of app/AppKernel.php So, in short if you want to handle it yourself switch back to app/AppCache.php in your 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);
In details you should read about Symfony http cache