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

Commitd512875

Browse files
committed
Updated http_cache/* articles to Symfony 4
1 parent7699ca2 commitd512875

File tree

4 files changed

+24
-26
lines changed

4 files changed

+24
-26
lines changed

‎http_cache.rst‎

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -81,18 +81,15 @@ Enabling the proxy is easy: each application comes with a caching kernel (``AppC
8181
that wraps the default one (``AppKernel``). The caching Kernel *is* the reverse
8282
proxy.
8383

84-
To enable caching, modify the code of your front controller. You can also make these
85-
changes to ``index.php`` to add caching to the ``dev`` environment::
84+
To enable caching, modify the code of your ``index.php`` front controller::
8685

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

9089
// ...
91-
$kernel = new AppKernel('prod', false);
92-
$kernel->loadClassCache();
90+
$kernel = new Kernel($_SERVER['APP_ENV'] ?? 'dev', $_SERVER['APP_DEBUG'] ?? false);
9391

94-
// add (or uncomment) this new line!
95-
// wrap the default Kernel with the AppCache one
92+
// add (or uncomment) this line to wrap the default Kernel with the AppCache one
9693
$kernel = new AppCache($kernel);
9794

9895
$request = Request::createFromGlobals();
@@ -120,7 +117,9 @@ finely tuned via a set of options you can set by overriding the
120117
:method:`Symfony\\Bundle\\FrameworkBundle\\HttpCache\\HttpCache::getOptions`
121118
method::
122119

123-
// app/AppCache.php
120+
// src/AppCache.php
121+
namespace App;
122+
124123
use Symfony\Bundle\FrameworkBundle\HttpCache\HttpCache;
125124

126125
class AppCache extends HttpCache
@@ -137,10 +136,9 @@ method::
137136
For a full list of the options and their meaning, see the
138137
:method:`HttpCache::__construct() documentation <Symfony\\Component\\HttpKernel\\HttpCache\\HttpCache::__construct>`.
139138

140-
When you're in debug mode (either because your booting a ``debug`` kernel, like
141-
in ``index.php`` *or* you manually set the ``debug`` option to true), Symfony
142-
automatically adds an ``X-Symfony-Cache`` header to the response. Use this to get
143-
information about cache hits and misses.
139+
When you're in debug mode (the second argument of ``Kernel`` constructor in the
140+
front controller is ``true``), Symfony automatically adds an ``X-Symfony-Cache``
141+
header to the response. Use this to get information about cache hits and misses.
144142

145143
.. _http-cache-symfony-versus-varnish:
146144

@@ -150,7 +148,7 @@ information about cache hits and misses.
150148
website or when you deploy your website to a shared host where you cannot
151149
install anything beyond PHP code. But being written in PHP, it cannot
152150
be as fast as a proxy written in C.
153-
151+
154152
Fortunately, since all reverse proxies are effectively the same, you should
155153
be able to switch to something more robust - like Varnish - without any problems.
156154
See:doc:`How to use Varnish</http_cache/varnish>`
@@ -192,7 +190,7 @@ These four headers are used to help cache your responses via *two* different mod
192190

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

198196
As a web developer, you are strongly urged to read the specification. Its
@@ -214,7 +212,7 @@ The *easiest* way to cache a response is by caching it for a specific amount of
214212
use Symfony\Component\HttpFoundation\Response;
215213
// ...
216214

217-
public functionindexAction()
215+
public functionindex()
218216
{
219217
// somehow create a Response object, like by rendering a template
220218
$response = $this->render('blog/index.html.twig', []);

‎http_cache/cache_invalidation.rst‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ cache instead of going to the application to get a response.
5050
Here is how you can configure the Symfony reverse proxy to support the
5151
``PURGE`` HTTP method::
5252

53-
//app/AppCache.php
53+
//src/AppCache.php
5454

5555
use Symfony\Bundle\FrameworkBundle\HttpCache\HttpCache;
5656
use Symfony\Component\HttpFoundation\Request;

‎http_cache/esi.rst‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,14 @@ First, to use ESI, be sure to enable it in your application configuration:
6262

6363
..code-block::yaml
6464
65-
#app/config/config.yml
65+
# config/packages/framework.yaml
6666
framework:
6767
# ...
6868
esi:{ enabled: true }
6969
7070
..code-block::xml
7171
72-
<!--app/config/config.xml-->
72+
<!-- config/packages/framework.xml-->
7373
<?xml version="1.0" encoding="UTF-8" ?>
7474
<containerxmlns="http://symfony.com/schema/dic/symfony"
7575
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
@@ -87,7 +87,7 @@ First, to use ESI, be sure to enable it in your application configuration:
8787
8888
..code-block::php
8989
90-
//app/config/config.php
90+
// config/packages/framework.php
9191
$container->loadFromExtension('framework', array(
9292
// ...
9393
'esi' => array('enabled' => true),
@@ -104,7 +104,7 @@ independent of the rest of the page.
104104
// ...
105105
class DefaultController extends Controller
106106
{
107-
public functionaboutAction()
107+
public functionabout()
108108
{
109109
$response = $this->render('static/about.html.twig');
110110
// set the shared max age - which also marks the response as public
@@ -195,7 +195,7 @@ of the master page.
195195
// ...
196196
class NewsController extends Controller
197197
{
198-
public functionlatestAction($maxPerPage)
198+
public functionlatest($maxPerPage)
199199
{
200200
// ...
201201
$response->setSharedMaxAge(60);
@@ -220,14 +220,14 @@ that must be enabled in your configuration:
220220

221221
..code-block::yaml
222222
223-
#app/config/config.yml
223+
# config/packages/framework.yaml
224224
framework:
225225
# ...
226226
fragments:{ path: /_fragment }
227227
228228
..code-block::xml
229229
230-
<!--app/config/config.xml-->
230+
<!-- config/packages/framework.xml-->
231231
<?xml version="1.0" encoding="UTF-8" ?>
232232
<containerxmlns="http://symfony.com/schema/dic/services"
233233
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
@@ -245,7 +245,7 @@ that must be enabled in your configuration:
245245
246246
..code-block::php
247247
248-
//app/config/config.php
248+
// config/packages/framework.php
249249
$container->loadFromExtension('framework', array(
250250
// ...
251251
'fragments' => array('path' => '/_fragment'),

‎http_cache/validation.rst‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ To see a simple implementation, generate the ETag as the md5 of the content::
6666

6767
class DefaultController extends Controller
6868
{
69-
public functionhomepageAction(Request $request)
69+
public functionhomepage(Request $request)
7070
{
7171
$response = $this->render('static/homepage.html.twig');
7272
$response->setEtag(md5($response->getContent()));
@@ -131,7 +131,7 @@ header value::
131131

132132
class ArticleController extends Controller
133133
{
134-
public functionshowAction(Article $article, Request $request)
134+
public functionshow(Article $article, Request $request)
135135
{
136136
$author = $article->getAuthor();
137137

@@ -190,7 +190,7 @@ exposing a simple and efficient pattern::
190190

191191
class ArticleController extends Controller
192192
{
193-
public functionshowAction($articleSlug, Request $request)
193+
public functionshow($articleSlug, Request $request)
194194
{
195195
// Get the minimum information to compute
196196
// the ETag or the Last-Modified value

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp