Skip to content

Commit 0f71038

Browse files
committed
Docs for new cache plugin option
1 parent 395e79c commit 0f71038

File tree

1 file changed

+30
-16
lines changed

1 file changed

+30
-16
lines changed

plugins/cache.rst

+30-16
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,34 @@ control headers from the server as specified in :rfc:`7234`. It needs a
3333
[$cachePlugin]
3434
);
3535

36+
.. note::
37+
38+
Since v1.3.0 does the ``CachePlugin`` have 2 factory methods to easily setup the plugin by caching type.
39+
40+
.. code-block:: php
41+
42+
$cachePlugin = CachePlugin::clientCache($pool, $streamFactory, $options); // Which allows caching responses with the 'private' or 'no-store' cache directive
43+
$cachePlugin = CachePlugin::serverCache($pool, $streamFactory, $options); // Returns a cache plugin with the current default behavior
44+
3645
Options
3746
-------
3847

3948
The third parameter to the ``CachePlugin`` constructor takes an array of options. The available options are:
4049

41-
+---------------------------+---------------------+------------------------------------------------------+
42-
| Name | Default value | Description |
43-
+===========================+=====================+======================================================+
44-
| ``default_ttl`` | ``0`` | The default max age of a Response |
45-
+---------------------------+---------------------+------------------------------------------------------+
46-
| ``respect_cache_headers`` | ``true`` | Whether we should care about cache headers or not |
47-
+---------------------------+---------------------+------------------------------------------------------+
48-
| ``cache_lifetime`` | 30 days | The minimum time we should store a cache item |
49-
+---------------------------+---------------------+------------------------------------------------------+
50-
| ``methods`` | ``['GET', 'HEAD']`` | Which request methods to cache |
51-
+---------------------------+---------------------+------------------------------------------------------+
50+
+---------------------------------------+----------------------------------------------------+-----------------------------------------------------------------------+
51+
| Name | Default value | Description |
52+
+=======================================+====================================================+=======================================================================+
53+
| ``default_ttl`` | ``0`` | The default max age of a Response |
54+
+---------------------------------------+----------------------------------------------------+-----------------------------------------------------------------------+
55+
| ``respect_cache_headers`` | ``true`` | Whether we should care about cache headers or not |
56+
| | | * This option is deprecated. Use `respect_response_cache_directives` |
57+
+---------------------------------------+----------------------------------------------------+-----------------------------------------------------------------------+
58+
| ``cache_lifetime`` | 30 days | The minimum time we should store a cache item |
59+
+---------------------------------------+----------------------------------------------------+-----------------------------------------------------------------------+
60+
| ``methods`` | ``['GET', 'HEAD']`` | Which request methods to cache |
61+
+---------------------------------------+----------------------------------------------------+-----------------------------------------------------------------------+
62+
| ``respect_response_cache_directives`` | ``['no-cache', 'private', 'max-age', 'no-store']`` | A list of cache directives to respect when caching responses |
63+
+---------------------------------------+----------------------------------------------------+-----------------------------------------------------------------------+
5264

5365
.. note::
5466

@@ -68,7 +80,7 @@ for the default time to live. The options below will cache all responses for one
6880

6981
$options = [
7082
'default_ttl' => 3600, // cache for one hour
71-
'respect_cache_headers' => false,
83+
'respect_response_cache_directives' => [],
7284
];
7385

7486
Semantics of null values
@@ -81,7 +93,7 @@ Store a response as long the cache implementation allows::
8193

8294
$options = [
8395
'default_ttl' => null,
84-
'respect_cache_headers' => false,
96+
'respect_response_cache_directives' => [],
8597
'cache_lifetime' => null,
8698
];
8799

@@ -90,7 +102,7 @@ Ask the server if the response is valid at most ever hour. Store the cache item
90102

91103
$options = [
92104
'default_ttl' => 3600,
93-
'respect_cache_headers' => false,
105+
'respect_response_cache_directives' => [],
94106
'cache_lifetime' => null,
95107
];
96108

@@ -100,7 +112,7 @@ removed from the cache::
100112

101113
$options = [
102114
'default_ttl' => 3600,
103-
'respect_cache_headers' => false,
115+
'respect_response_cache_directives' => [],
104116
'cache_lifetime' => 86400*365, // one year
105117
];
106118

@@ -125,7 +137,9 @@ to include them. You can specify any uppercase request method which conforms to
125137
Cache Control Handling
126138
----------------------
127139

128-
This plugin does not cache responses with ``no-store`` or ``private`` instructions.
140+
By default this plugin does not cache responses with ``no-store`` or ``private`` instructions. If you need to cache
141+
responses with these cache directives you should setup the plugin with ``CachePlugin::clientCache($pool, $streamFactory, $options);``
142+
or change the ``respect_response_cache_directives`` to your needs.
129143

130144
It does store responses with cookies or a ``Set-Cookie`` header. Be careful with
131145
the order of your plugins.

0 commit comments

Comments
 (0)