@@ -105,14 +105,15 @@ independently of the rest of the page::
105
105
public function about()
106
106
{
107
107
$response = $this->render('static/about.html.twig');
108
- // sets the shared max age - which also marks the response as public
109
- $response->setSharedMaxAge (600);
108
+ $ response->setPublic();
109
+ $response->setMaxAge (600);
110
110
111
111
return $response;
112
112
}
113
113
}
114
114
115
- In this example, the full-page cache has a lifetime of ten minutes.
115
+ In this example, the response is marked as public to make the full page
116
+ cacheable for all requests with a lifetime of ten minutes.
116
117
Next, include the news ticker in the template by embedding an action.
117
118
This is done via the ``render() `` helper (for more details, see how to
118
119
:ref: `embed controllers in templates <templates-embed-controllers >`).
@@ -170,14 +171,19 @@ of the master page::
170
171
public function latest($maxPerPage)
171
172
{
172
173
// ...
173
- $response->setSharedMaxAge(60);
174
+ $response->setPublic();
175
+ $response->setMaxAge(60);
174
176
175
177
return $response;
176
178
}
177
179
}
178
180
179
- With ESI, the full page cache will be valid for 600 seconds, but the news
180
- component cache will only last for 60 seconds.
181
+ In this example, the embedded action is cached publicly too because the contents
182
+ are the same for all requests. However, in other cases you may need to make this
183
+ response non-public and even non-cacheable, depending on your needs.
184
+
185
+ Putting all the above code together, with ESI the full page cache will be valid
186
+ for 600 seconds, but the news component cache will only last for 60 seconds.
181
187
182
188
.. _http_cache-fragments :
183
189
@@ -233,14 +239,6 @@ possible.
233
239
signed when using the fragment renderer and the ``render_esi `` Twig
234
240
function.
235
241
236
- .. note ::
237
-
238
- Once you start using ESI, remember to always use the ``s-maxage ``
239
- directive instead of ``max-age ``. As the browser only ever receives the
240
- aggregated resource, it is not aware of the sub-components, and so it will
241
- obey the ``max-age `` directive and cache the entire page. And you don't
242
- want that.
243
-
244
242
The ``render_esi `` helper supports two other useful options:
245
243
246
244
``alt ``
0 commit comments