Is it fine if first response is private with AppCache (Symfony2)?

前端 未结 2 800
小鲜肉
小鲜肉 2021-01-30 19:18

I\'m trying to use http caching. In my controller I\'m setting a response as follows:

$response->setPublic();
$response->setMaxAge(120);
$response->set         


        
2条回答
  •  孤独总比滥情好
    2021-01-30 19:44

    I have faced same problem. I had to supply 'public' headers my cdn. By default when gateway caching is enabled in prod mode, it returns 200 OK with private, nocache must validate headers.

    I solved problem this way.

    In app.php, before I send response to user ($respond->send), I have overwritten the cache control header to blank and set cache headers to public and max age(some value).

    //code snippet from app.php

        $response = $kernel->handle($request);
        $response->headers->set('Cache-Control', '');
        $response->setPublic();
        $response->setMaxAge(86400);
        $response->send();        
    

提交回复
热议问题