I'm playing with HTTP Cache Validation - Validation with the ETag Header
In my controller I have:
// ... get the $data and $myObject somehow ...
$response = $this->json($data);
$response->setEtag($myObject->getDateModified()->format("Y-m-d H:i:s")); // getDateModified() returns a DateTime
$response->setPublic();
return $response;
The first time the page is loaded after deleting the cache, the controller is run and everything is fine. But starting from the second time I just get:
FatalErrorException in classes.php line 3353: Error: Cannot declare class Symfony\Component\HttpFoundation\Response, because the name is already in use
this probleme is there as soon as I use $response->setPublic();
What is causing the problem? Am I doing anything wrong?
I found this, maybe it could help you https://github.com/contao/core-bundle/issues/643
They suggest removing the line
$kernel->loadClassCache();
fromapp.php
.EDIT: I removed line
$kernel->loadClassCache();
and there is no more errors and http cache is working normally.Also, here is extra info: https://github.com/symfony/symfony/issues/20668