Symfony Cache Validation error: Cannot declare class Response after using setPublic()

835 views Asked by At

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?

1

There are 1 answers

6
Matko Đipalo On BEST ANSWER

I found this, maybe it could help you https://github.com/contao/core-bundle/issues/643

They suggest removing the line $kernel->loadClassCache(); from app.php.

It is a speedup attempt which preloads classes which are needed in most requests. This is however obsolete in PHP7.0 and marginal in PHP 5.6 - therefore it is save to remove it.

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