10000 Merge branch '6.0' into 6.1 · symfony/symfony-docs@abf391b · GitHub
[go: up one dir, main page]

Skip to content

Commit abf391b

Browse files
committed
Merge branch '6.0' into 6.1
* 6.0: Update section about http cache Update doctrine.rst
2 parents eaf27f7 + af41b73 commit abf391b

File tree

3 files changed

+117
-69
lines changed

3 files changed

+117
-69
lines changed

doctrine.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,10 +397,10 @@ you can query the database directly:
397397

398398
.. code-block:: terminal
399399
400-
$ php bin/console doctrine:query:sql 'SELECT * FROM product'
400+
$ php bin/console dbal:run-sql 'SELECT * FROM product'
401401
402402
# on Windows systems not using Powershell, run this command instead:
403-
# php bin/console doctrine:query:sql "SELECT * FROM product"
403+
# php bin/console dbal:run-sql "SELECT * FROM product"
404404
405405
Take a look at the previous example in more detail:
406406

http_cache.rst

Lines changed: 23 additions & 66 deletions
1E0A
Original file line numberDiff line numberDiff line change
@@ -77,82 +77,39 @@ but it is a great way to start.
7777

7878
For details on setting up Varnish, see :doc:`/http_cache/varnish`.
7979

80-
To enable the proxy, first create a caching kernel::
80+
Use the ``framework.http_cache`` option to enable the proxy for the
81+
:ref:`prod environment <configuration-environments>`:
8182

82-
// src/CacheKernel.php
83-
namespace App;
83+
.. configuration-block::
8484

85-
use Symfony\Bundle\FrameworkBundle\HttpCache\HttpCache;
85+
.. code-block:: yaml
8686
87-
class CacheKernel extends HttpCache
88-
{
89-
}
90-
91-
Modify the code of your front controller to wrap the default kernel into the
92-
caching kernel:
87+
# config/packages/framework.yaml
88+
when@prod:
89+
framework:
90+
http_cache: true
9391
94-
.. code-block:: diff
92+
.. code-block:: php
9593
96-
// public/index.php
94+
// config/packages/framework.php
95+
use Symfony\Config\FrameworkConfig;
9796
98-
+ use App\CacheKernel;
99-
use App\Kernel;
100-
101-
// ...
102-
$kernel = new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);
103-
+ // Wrap the default Kernel with the CacheKernel one in 'prod' environment
104-
+ if ('prod' === $kernel->getEnvironment()) {
105-
+ return new CacheKernel($kernel);
106-
+ }
107-
return $kernel;
97+
return static function (FrameworkConfig $framework) use ($env) {
98+
if ('prod' === $env) {
99+
$framework->httpCache()->enabled(true);
100+
}
101+
};
108102
109-
110-
The caching kernel will immediately act as a reverse proxy: caching responses
103+
The kernel will immediately act as a reverse proxy: caching responses
111104
from your application and returning them to the client.
112105

113-
.. caution::
114-
115-
If you're using the :ref:`framework.http_method_override <configuration-framework-http_method_override>`
116-
option to read the HTTP method from a ``_method`` parameter, see the
117-
above link for a tweak you need to make.
118-
119-
.. tip::
120-
121-
The cache kernel has a special ``getLog()`` method that returns a string
122-
representation of what happened in the cache layer. In the development
123-
environment, use it to debug and validate your cache strategy::
124-
125-
error_log($kernel->getLog());
126-
127-
The ``CacheKernel`` object has a sensible default configuration, but it can be
128-
finely tuned via a set of options you can set by overriding the
129-
:method:`Symfony\\Bundle\\FrameworkBundle\\HttpCache\\HttpCache::getOptions`
130-
method::
131-
132-
// src/CacheKernel.php
133-
namespace App;
134-
135-
use Symfony\Bundle\FrameworkBundle\HttpCache\HttpCache;
136-
137-
class CacheKernel extends HttpCache
138-
{
139-
protected function getOptions(): array
140-
{
141-
return [
142-
'default_ttl' => 0,
143-
// ...
144-
];
145-
}
146-
}
147-
148-
For a full list of the options and their meaning, see the
149-
:method:`HttpCache::__construct() documentation <Symfony\\Component\\HttpKernel\\HttpCache\\HttpCache::__construct>`.
106+
The proxy has a sensible default configuration, but it can be
107+
finely tuned via `a set of options <configuration-framework-http_cache>`.
150108

151-
When you're in debug mode (the second argument of ``Kernel`` constructor in the
152-
front controller is ``true``), Symfony automatically adds an ``X-Symfony-Cache``
153-
header to the response. You can also use the ``trace_level`` config
154-
option and set it to either ``none``, ``short`` or ``full`` to
155-
add this information.
109+
When in :ref:`debug mode <debug-mode>`, Symfony automatically adds an
110+
``X-Symfony-Cache`` header to the response. You can also use the ``trace_level``
111+
config option and set it to either ``none``, ``short`` or ``full`` to add this
112+
information.
156113

157114
``short`` will add the information for the main request only.
158115
It's written in a concise way that makes it easy to record the

reference/configuration/framework.rst

Lines changed: 92 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,98 @@ will invalidate all signed URIs and Remember Me cookies. That's why, after
5353
changing this value, you should regenerate the application cache and log
5454
out all the application users.
5555

56-
.. _configuration-framework-http_method_override:
56+
.. _configuration-framework-http_cache:
57+
58+
http_cache
59+
~~~~~~~~~~
60+
61+
enabled
62+
.......
63+
64+
**type**: ``boolean`` **default**: ``false``
65+
66+
debug
67+
.....
68+
69+
**type**: ``boolean`` **default**: ``%kernel.debug%``
70+
71+
If true, exceptions are thrown when things go wrong. Otherwise, the cache will
72+
try to carry on and deliver a meaningful response.
73+
74+
trace_level
75+
...........
76+
77+
**type**: ``string`` **possible values**: ``'none'``, ``'short'`` or ``'full'``
78+
79+
For 'short', a concise trace of the main request will be added as an HTTP header.
80+
'full' will add traces for all requests (including ESI subrequests).
81+
(default: 'full' if in debug; 'none' otherwise)
82+
83+
trace_header
84+
............
85+
86+
**type**: ``string``
87+
88+
Header name to use for traces. (default: X-Symfony-Cache)
89+
90+
default_ttl
91+
...........
92+
93+
**type**: ``integer``
94+
95+
The number of seconds that a cache entry should be considered fresh when no
96+
explicit freshness information is provided in a response. Explicit
97+
Cache-Control or Expires headers override this value. (default: 0)
98+
99+
private_headers
100+
...............
101+
102+
**type**: ``array``
103+
104+
Set of request headers that trigger "private" cache-control behavior on responses
105+
that don't explicitly state whether the response is public or private via a
106+
Cache-Control directive. (default: Authorization and Cookie)
107+
108+
allow_reload
109+
............
110+
111+
**type**: ``string``
112+
113+
Specifies whether the client can force a cache reload by including a
114+
Cache-Control "no-cache" directive in the request. Set it to ``true``
115+
for compliance with RFC 2616. (default: false)
116+
117+
allow_revalidate
118+
................
119+
120+
**type**: ``string``
121+
122+
Specifies whether the client can force a cache revalidate by including a
123+
Cache-Control "max-age=0" directive in the request. Set it to ``true``
124+
for compliance with RFC 2616. (default: false)
125+
126+
stale_while_revalidate
127+
......................
128+
129+
**type**: ``integer``
130+
131+
Specifies the default number of seconds (the granularity is the second as the
132+
Response TTL precision is a second) during which the cache can immediately return
133+
a stale response while it revalidates it in the background (default: 2).
134+
This setting is overridden by the stale-while-revalidate HTTP Cache-Control
135+
extension (see RFC 5861).
136+
137+
stale_if_error
138+
..............
139+
140+
**type**: ``integer``
141+
142+
Specifies the default number of seconds (the granularity is the second) during
143+
which the cache can serve a stale response when an error is encountered
144+
(default: 60). This setting is overridden by the stale-if-error HTTP
145+
Cache-Control extension (see RFC 5861).
146+
147+
.. _configuration-framework-http_method_override:
57148

58149
http_method_override
59150
~~~~~~~~~~~~~~~~~~~~

0 commit comments

Comments
 (0)
0