Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Update HttpCache kernel documentation for Symfony 4#8696

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletionconfiguration/front_controllers_and_kernel.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -44,7 +44,7 @@ to `decorate`_ the kernel with additional features. Examples include:

* Configuring the autoloader or adding additional autoloading mechanisms;
* Adding HTTP level caching by wrapping the kernel with an instance of
:ref:`AppCache <symfony-gateway-cache>`;
:ref:`HttpCache <symfony-gateway-cache>`;
* Enabling the :doc:`Debug Component </components/debug>`.

The front controller can be chosen by requesting URLs like:
Expand Down
36 changes: 20 additions & 16 deletionshttp_cache.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -77,23 +77,27 @@ but is a great way to start.

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

Enabling the proxy is easy: each application comes with a caching kernel (``AppCache``)
that wraps the default one (``AppKernel``). The caching Kernel *is* the reverse
proxy.
To enable the proxy, first create a caching kernel::

To enable caching, modify the code of your front controller. You can also make these
changes to ``index.php`` to add caching to the ``dev`` environment::
// src/CacheKernel.php
use Symfony\Bundle\FrameworkBundle\HttpCache\HttpCache;

class CacheKernel extends HttpCache
{
}

Modify the code of your front controller to wrap the default kernel into the
caching kernel:

.. code-block:: diff

// public/index.php
use Symfony\Component\HttpFoundation\Request;

// ...
$kernel = new AppKernel('prod', false);
$kernel->loadClassCache();
$kernel = new Kernel($_SERVER['APP_ENV'] ?? 'dev', $_SERVER['APP_DEBUG'] ?? ('prod' !== ($_SERVER['APP_ENV'] ?? 'dev')));

// add (or uncomment) this new line!
// wrap the default Kernel with the AppCache one
$kernel = new AppCache($kernel);
+ // Wrap the default Kernel with the CacheKernel one
+ $kernel = new CacheKernel($kernel);

$request = Request::createFromGlobals();
// ...
Expand All@@ -115,15 +119,15 @@ from your application and returning them to the client.

error_log($kernel->getLog());

The ``AppCache`` object has a sensible default configuration, but it can be
The ``CacheKernel`` object has a sensible default configuration, but it can be
finely tuned via a set of options you can set by overriding the
:method:`Symfony\\Bundle\\FrameworkBundle\\HttpCache\\HttpCache::getOptions`
method::

//app/AppCache.php
//src/CacheKernel.php
use Symfony\Bundle\FrameworkBundle\HttpCache\HttpCache;

classAppCache extends HttpCache
classCacheKernel extends HttpCache
{
protected function getOptions()
{
Expand All@@ -150,7 +154,7 @@ information about cache hits and misses.
website or when you deploy your website to a shared host where you cannot
install anything beyond PHP code. But being written in PHP, it cannot
be as fast as a proxy written in C.

Fortunately, since all reverse proxies are effectively the same, you should
be able to switch to something more robust - like Varnish - without any problems.
See :doc:`How to use Varnish </http_cache/varnish>`
Expand DownExpand Up@@ -192,7 +196,7 @@ These four headers are used to help cache your responses via *two* different mod

All of the HTTP headers you'll read about are *not* invented by Symfony! They're
part of an HTTP specification that's used by sites all over the web. To dig deeper
into HTTP Caching, check out the documents `RFC 7234 - Caching`_ and
into HTTP Caching, check out the documents `RFC 7234 - Caching`_ and
`RFC 7232 - Conditional Requests`_.

As a web developer, you are strongly urged to read the specification. Its
Expand Down
8 changes: 4 additions & 4 deletionshttp_cache/cache_invalidation.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -47,17 +47,17 @@ the word "PURGE" is a convention, technically this can be any string) instead
of ``GET`` and make the cache proxy detect this and remove the data from the
cache instead of going to the application to get a response.

Here is how you can configure the Symfony reverse proxyto support the
``PURGE`` HTTP method::
Here is how you can configure the Symfony reverse proxy(See :doc:`/http_cache`)
to support the``PURGE`` HTTP method::

//app/AppCache.php
//src/CacheKernel.php

use Symfony\Bundle\FrameworkBundle\HttpCache\HttpCache;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
// ...

classAppCache extends HttpCache
classCacheKernel extends HttpCache
{
protected function invalidate(Request $request, $catch = false)
{
Expand Down
6 changes: 3 additions & 3 deletionsreference/configuration/framework.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -173,17 +173,17 @@ named ``kernel.http_method_override``.

.. caution::

If you're using the :ref:`AppCache Reverse Proxy <symfony2-reverse-proxy>`
If you're using the :ref:`HttpCache Reverse Proxy <symfony2-reverse-proxy>`
with this option, the kernel will ignore the ``_method`` parameter,
which could lead to errors.

To fix this, invoke the ``enableHttpMethodParameterOverride()`` method
before creating the ``Request`` object::

//web/app.php
//public/index.php

// ...
$kernel = newAppCache($kernel);
$kernel = newCacheKernel($kernel);

Request::enableHttpMethodParameterOverride(); // <-- add this line
$request = Request::createFromGlobals();
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp