0

I am using the symfony reverse proxy for cache.

I have 2 privates caches. You can imagine it as a private online-shop: the list of items is my first private cache because of the needed authentification of the user. the component is my second private cache because it contains dynamic data, for the logged user only.

AppKernel

$kernel = new AppKernel($env, $debug);
$kernel->loadClassCache();
$kernel = new AppCache($kernel); //  <-- enable cache

config.yml

framework:
    esi:       { enabled: true }
    fragments: { path: /_proxy }

page.html.twig

<header>{{  render_esi(controller('AppBundle:Menu:displayMenu')) }}</header>
<main>cached private stuff</main>

PageController - IndexAction:

    $response = new Response();
    $response->setPrivate();
    $response->setMaxAge(180); // 3 minutes for the content
    return $this->render('page.html.twig', [], $response);

MenuController - DisplayMenuAction:

    $response = new Response();
    $response->setPrivate();
    $response->setMaxAge(10); // only 10 second for the menu
    return $this->render('page.html.twig', [], $response);

In prod environement, it display in the cache header

Cache-Control:max-age=0, public, s-maxage=15

I have 2 private caches, why the cache header is sent as public?

Edit:

When I comment the esi_render tag, the page has its cache private with 3 minutes. (as expected)

I have check I have no other listener with the command bin/console debug:container --tag=kernel.event_subscriber

goto
  • 7,908
  • 10
  • 48
  • 58
  • You probably set another public cache (in listener maybe?) because: "Symfony conservatively defaults each response to be private. To take advantage of shared caches (like the Symfony reverse proxy), the response will need to be explicitly set as public." – malcolm Nov 03 '16 at 20:56
  • @malcom I do not have any public cache in the application. At least not custom – goto Nov 04 '16 at 09:54

0 Answers0