Skip to content

Commit c61c5ff

Browse files
committed
minor #9667 Documented HTTP caching and user sessions (Toflar, javiereguiluz)
This PR was merged into the master branch. Discussion ---------- Documented HTTP caching and user sessions As promised in #9647. Commits ------- ecb0ac4 Minor reword to make it more concise 9b37b0e Documented HTTP caching and user sessions
2 parents 1ac87d0 + ecb0ac4 commit c61c5ff

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

http_cache.rst

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,31 @@ When pages contain dynamic parts, you may not be able to cache entire pages,
353353
but only parts of it. Read :doc:`/http_cache/esi` to find out how to configure
354354
different cache strategies for specific parts of your page.
355355

356+
HTTP Caching and User Sessions
357+
------------------------------
358+
359+
Whenever the session is started during a request, Symfony turns the response
360+
into a private non-cacheable response. This is the best default behavior to not
361+
cache private user information (e.g. a shopping cart, a user profile details,
362+
etc.) and expose it to other visitors.
363+
364+
However, even requests making use of the session can be cached under some
365+
circumstances. For example, information related to some user group could be
366+
cached for all the users belonging to that group. Handling these advanced
367+
caching scenarios is out of the scope of Symfony, but they can be solved with
368+
the `FOSHttpCacheBundle`_.
369+
370+
In order to disable the default Symfony behavior that makes requests using the
371+
session uncacheable, add the following internal header to your response and
372+
Symfony won't modify it::
373+
374+
use Symfony\Component\HttpKernel\EventListener\AbstractSessionListener;
375+
376+
$response->headers->set(AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER, 'true');
377+
378+
.. versionadded:: 4.1
379+
The ``NO_AUTO_CACHE_CONTROL_HEADER`` header was introduced in Symfony 4.1.
380+
356381
Summary
357382
-------
358383

0 commit comments

Comments
 (0)