Skip to content

Commit c9ee056

Browse files
dbuddeboer
authored andcommitted
various tweaks and cleanups
1 parent 83a794e commit c9ee056

File tree

21 files changed

+142
-64
lines changed

21 files changed

+142
-64
lines changed

DependencyInjection/Configuration.php

-4
Original file line numberDiff line numberDiff line change
@@ -464,10 +464,6 @@ private function addFlashMessageSection(ArrayNodeDefinition $rootNode)
464464
->defaultFalse()
465465
->info('Whether the cookie should only be transmitted over a secure HTTPS connection from the client.')
466466
->end()
467-
->scalarNode('httpOnly')
468-
->defaultTrue()
469-
->info('Whether the cookie will be made accessible only through the HTTP protocol.')
470-
->end()
471467
->end()
472468
->end()
473469
->end();

EventListener/FlashMessageSubscriber.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public function onKernelResponse(FilterResponseEvent $event)
9898
$this->options['path'],
9999
$this->options['host'],
100100
$this->options['secure'],
101-
$this->options['httpOnly']
101+
false
102102
);
103103

104104
$response->headers->setCookie($cookie);

Resources/doc/features.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Features
22
========
33

4-
This part introduces the bundle’s features. Each feature links to the Reference
5-
chapter for a fuller explanation.
4+
This part introduces the bundle’s features. Each feature section links to the
5+
corresponding reference section.
66

77
.. toctree::
88

Resources/doc/features/headers.rst

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
Caching Headers
22
===============
33

4+
**Prerequisites**: *None*
5+
46
You can configure HTTP caching headers based on request and response properties.
57
This configuration approach is more convenient than `manually setting cache headers`_
68
and an alternative to `setting caching headers through annotations`_.

Resources/doc/features/helpers/flash-message.rst

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
Flash Message Subscriber
22
========================
33

4+
**Prerequisites**: *None*
5+
46
When flash messages are rendered into the content of a page, you can't cache
57
the page anymore. When enabled, this subscriber reads all flash messages into a
68
cookie, leading to them not being there anymore when rendering the template.
@@ -17,11 +19,7 @@ the options under ``flash_message``.
1719
# app/config.yml
1820
fos_http_cache:
1921
flash_message:
20-
name: flashes
21-
path: /
22-
host: null
23-
secure: false
24-
httpOnly: false
22+
enabled: true
2523
2624
On the client side, you need some JavaScript code that reads out the flash
2725
messages from the cookie and writes them into the DOM, then deletes the cookie

Resources/doc/features/invalidation.rst

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
Invalidation
22
============
33

4+
**Prerequisites**: :ref:`Configure caching proxy <foshttpcache:proxy-configuration>`.
5+
46
By *invalidating* a piece of content, you tell your HTTP caching proxy (Varnish
57
or Nginx) to no longer serve it to clients. When next requested, the proxy will
68
fetch a fresh copy from the backend application and serve that instead. By

Resources/doc/features/tagging.rst

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
Tagging
22
=======
33

4+
**Prerequisites**: :ref:`Configure caching proxy for banning <foshttpcache:varnish-configuration#ban>` (only supported with Varnish).
5+
46
If your application has many intricate relationships between cached items,
57
which makes it complex to invalidate them by route, cache tagging will be
68
useful.

Resources/doc/features/user-context.rst

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
User Context
22
============
33

4+
**Prerequisites**: :ref:`Configure caching proxy for user context <foshttpcache:varnish-configuration#user-context>` (only supported with Varnish).
5+
46
If your application serves different content depending on the user’s group
5-
or context (guest, editor, admin), you can can that content by user context.
7+
or context (guest, editor, admin), you can cache that content per user context.
68
Each user context (group) gets its own unique hash, which is then used to vary
79
content on. The event subscriber responds to hash requests and sets the Vary
810
header. This way, you can differentiate your content between user groups while

Resources/doc/includes/enabled.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
enabled
22
-------
33

4-
**type**: ``enum`` **default**: ``auto`` **options**: ``true``, ``false``, ``auto``
4+
**type**: ``enum``, **default**: ``auto``, **options**: ``true``, ``false``, ``auto``
55

66
Enabled by default if :ref:`ExpressionLanguage is installed <expression language requirement>`
77
and you have :doc:`configured a proxy client </reference/configuration/proxy-client>`.

Resources/doc/index.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ This is the documentation for the `FOSHttpCacheBundle <https://github.com/Friend
55
Use the FOSHttpCacheBundle to:
66

77
* set HTTP caching headers in your application configuration based on request
8-
properties such as path and controller
9-
* tag your response caches with annotations
10-
* invalidate cached paths, routes and tags with the FOSHttpCache_ library
8+
properties such as path and controller;
9+
* tag your response caches with annotations;
10+
* invalidate cached paths, routes and tags with the FOSHttpCache_ library;
1111
* differentiate cached content per user type.
1212

1313
Contents

Resources/doc/overview.rst

+8-2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ Then add the bundle to your application:
3030
);
3131
}
3232
33+
For most features, you also need to :ref:`configure a caching proxy <foshttpcache:proxy-configuration>`.
34+
3335
.. _requirements:
3436

3537
Requirements
@@ -72,8 +74,12 @@ later, you need to explicitly add the component:
7274
7375
$ composer require symfony/expression-language
7476
75-
Now you can configure the bundle under the ``fos_http_cache`` key as explained
76-
in the :doc:`reference/configuration` section.
77+
Configuration
78+
-------------
79+
80+
Now you can configure the bundle under the ``fos_http_cache`` key. The
81+
:doc:`features` section contains configuration examples, for
82+
a reference see the :doc:`reference/configuration` section.
7783

7884
Functionality
7985
-------------

Resources/doc/reference/annotations.rst

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ actions are executed.
66

77
.. note::
88

9-
Make sure to :ref:`install the dependencies first <requirements>`.
9+
Annotations need the SensioFrameworkExtraBundle. Some features also need
10+
the ExpressionLanguage. Make sure to
11+
:ref:`installed the dependencies first <requirements>`.
1012

1113
.. _invalidatepath:
1214

Original file line numberDiff line numberDiff line change
@@ -1,4 +1,54 @@
11
Flash Message Configuration
22
===========================
33

4-
TODO
4+
The :doc:`flash message listener <../../features/helpers/flash-message>` is a
5+
tool to avoid rendering the flash message into the content of a page. It is
6+
another building brick for caching pages for logged in users.
7+
8+
.. code-block:: yaml
9+
10+
# app/config.yml
11+
fos_http_cache:
12+
flash_message:
13+
enabled: true
14+
name: flashes
15+
path: /
16+
host: null
17+
secure: false
18+
19+
enabled
20+
-------
21+
22+
**type**: ``boolean`` **default**: ``false``
23+
24+
This event subscriber is disabled by default. You can set enabled to true if
25+
the default values for all options are good for you. When you configure any of
26+
the options, the subscriber is automatically enabled.
27+
28+
name
29+
----
30+
31+
**type**: ``string`` **default**: ``flashes``
32+
Set the name of the cookie.
33+
34+
35+
path
36+
----
37+
38+
**type**: ``string`` **default**: ``/``
39+
40+
The cookie path to use.
41+
42+
host
43+
----
44+
45+
**type**: ``string``
46+
47+
Set the host for the cookie, e.g. to share among subdomains.
48+
49+
secure
50+
------
51+
52+
**type**: ``boolean`` **default**: ``false``
53+
54+
Whether the cookie may only be passed through HTTPS.

Resources/doc/reference/configuration/headers.rst

+46-29
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ cache_control
33

44
The configuration contains a number of *rules*. When a request matches the
55
parameters described in the ``match`` section, the headers as defined under
6-
``headers`` will be set on the response, if they are not already set.
6+
``headers`` will be set on the response, if they are not already set. Rules are
7+
checked in the order specified, where the first match wins.
78

89
.. code-block:: yaml
910
@@ -16,7 +17,11 @@ parameters described in the ``match`` section, the headers as defined under
1617
match:
1718
host: ^login.example.com$
1819
headers:
19-
cache_control: { public: false, max_age: 0, s_maxage: 0, last_modified: "-1 hour" }
20+
cache_control:
21+
public: false
22+
max_age: 0
23+
s_maxage: 0
24+
last_modified: "-1 hour"
2025
vary: [Accept-Encoding, Accept-Language]
2126
2227
# match all actions of a specific controller
@@ -25,52 +30,43 @@ parameters described in the ``match`` section, the headers as defined under
2530
attributes: { _controller: ^AcmeBundle:Default:.* }
2631
additional_cacheable_status: [400]
2732
headers:
28-
cache_control: { public: true, max_age: 15, s_maxage: 30, last_modified: "-1 hour" }
33+
cache_control:
34+
public: true
35+
max_age: 15
36+
s_maxage: 30
37+
last_modified: "-1 hour"
2938
3039
-
3140
match:
3241
path: ^/$
3342
headers:
34-
cache_control: { public: true, max_age: 64000, s_maxage: 64000, last_modified: "-1 hour" }
43+
cache_control:
44+
public: true
45+
max_age: 64000
46+
s_maxage: 64000
47+
last_modified: "-1 hour"
3548
vary: [Accept-Encoding, Accept-Language]
3649
3750
# match everything to set defaults
3851
-
3952
match:
4053
path: ^/
4154
headers:
42-
cache_control: { public: true, max_age: 15, s_maxage: 30, last_modified: "-1 hour" }
55+
cache_control:
56+
public: true
57+
max_age: 15
58+
s_maxage: 30
59+
last_modified: "-1 hour"
4360
4461
rules
4562
-----
4663

4764
**type**: ``array``
4865

49-
A set of cache control rules.
66+
A set of cache control rules consisting of *match* criteria and *header* instructions.
5067

5168
.. include:: /includes/match.rst
5269

53-
.. sidebar:: Merging headers
54-
55-
If the response already has certain cache directives set, they are not
56-
overwritten. The configuration can thus specify defaults that may be
57-
changed by controllers or services that handle the response, or ``@Cache``
58-
annotations.
59-
60-
The listener that applies the rules is triggered at priority 10, which
61-
makes it handle before the ``@Cache`` annotations from the
62-
SensioFrameworkExtraBundle are evaluated. Those annotations unconditionally
63-
overwrite cache directives.
64-
65-
The only exception is responses that *only* have the ``no-cache``
66-
directive. This is the default value for the cache control and there is no
67-
way to determine if it was manually set. If the full header is only
68-
``no-cache``, the whole cache control is overwritten.
69-
70-
You can prevent the cache control on specific requests by injecting the
71-
service ``fos_http_cache.event_listener.cache_control`` and calling
72-
``setSkip()`` on it. If this method is called, no cache rules are applied.
73-
7470
headers
7571
^^^^^^^
7672

@@ -107,6 +103,25 @@ headers
107103
In the ``headers`` section, you define what headers to set on the response if
108104
the request was matched.
109105

106+
Headers are **merged**. If the response already has certain cache directives
107+
set, they are not overwritten. The configuration can thus specify defaults
108+
that may be changed by controllers or services that handle the response, or
109+
``@Cache`` annotations.
110+
111+
The listener that applies the rules is triggered at priority 10, which
112+
makes it handle before the ``@Cache`` annotations from the
113+
SensioFrameworkExtraBundle are evaluated. Those annotations unconditionally
114+
overwrite cache directives.
115+
116+
The only exception is responses that *only* have the ``no-cache``
117+
directive. This is the default value for the cache control and there is no
118+
way to determine if it was manually set. If the full header is only
119+
``no-cache``, the whole cache control is overwritten.
120+
121+
You can prevent the cache control on specific requests by injecting the
122+
service ``fos_http_cache.event_listener.cache_control`` and calling
123+
``setSkip()`` on it. If this method is called, no cache rules are applied.
124+
110125
cache_control
111126
"""""""""""""
112127

@@ -227,7 +242,7 @@ reverse_proxy_ttl
227242

228243
**type**: ``integer``
229244

230-
For X-Reverse-Proxy-TTL for Custom Reverse Proxy Time-Outs
245+
Set a X-Reverse-Proxy-TTL header for reverse proxy time-outs not driven by ``s-maxage``.
231246

232247
By default, reverse proxies use the ``s-maxage`` of your ``Cache-Control`` header
233248
to know how long it should cache a page. But by default, the s-maxage is also
@@ -255,7 +270,9 @@ then use on the reverse proxy:
255270
-
256271
headers:
257272
reverse_proxy_ttl: 3600
258-
cache_control: { public: true, s_maxage: 60 }
273+
cache_control:
274+
public: true
275+
s_maxage: 60
259276
260277
This example adds the header ``X-Reverse-Proxy-TTL: 3600`` to your responses.
261278
Varnish by default knows nothing about this header. To make this solution work,

Resources/doc/reference/configuration/invalidation.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ rules
2828
**type**: ``array``
2929

3030
A set of invalidation rules. Each rule consists of a match definition and
31-
one or more routes that will be invalidated. The routes are invalidated when:
31+
one or more routes that will be invalidated. Rules are checked in the order
32+
specified, where the first match wins. The routes are invalidated when:
3233

3334
1. the HTTP request matches *all* criteria defined under ``match``
3435
2. the HTTP response is successful.

Resources/doc/reference/configuration/match.rst

+10-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1+
Matching
2+
========
3+
4+
Several parts of the configuration use ``match`` sections to limit
5+
configuration to specific requests and responses. Matches are used for
6+
:doc:`caching headers <headers>`, :doc:`invalidation <invalidation>` and
7+
:doc:`tag rules <tags>`.
18
match
2-
=====
9+
-----
310

411
**type**: ``array``
512

6-
Defines the matching part of a :doc:`cache <headers>`, :doc:`invalidation <invalidation>`
7-
or :doc:`tag rule <tags>`. It contains one or more match criteria for
8-
requests. All criteria are regular expressions. They are checked in the order
9-
specified, where the first match wins.
10-
11-
All matching criteria are regular expressions. For instance:
13+
A match contains one or more match criteria for requests. All matching criteria
14+
are regular expressions. For instance:
1215

1316
.. code-block:: yaml
1417

Resources/doc/reference/configuration/tags.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ rules
3030
**type**: ``array``
3131

3232
Write your tagging rules by combining a ``match`` definition with a ``tags``
33-
array. These tags will be set on the response when all of the following are true:
33+
array. Rules are checked in the order specified, where the first match wins.
34+
These tags will be set on the response when all of the following are true:
3435

3536
.. include:: /includes/safe.rst
3637

Tests/Resources/Fixtures/config/full.php

-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@
101101
'path' => '/x',
102102
'host' => 'y',
103103
'secure' => true,
104-
'httpOnly' => false,
105104
),
106105
'debug' => array(
107106
'header' => 'FOS-Cache-Debug',

0 commit comments

Comments
 (0)