Skip to content

Commit 663fdb4

Browse files
committed
Docs for new cache plugin option
1 parent 395e79c commit 663fdb4

File tree

1 file changed

+34
-16
lines changed

1 file changed

+34
-16
lines changed

Diff for: plugins/cache.rst

+34-16
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,38 @@ 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. See the
39+
example below.
40+
41+
.. code-block:: php
42+
43+
// This will allows caching responses with the 'private' and/or 'no-store' cache directives
44+
$cachePlugin = CachePlugin::clientCache($pool, $streamFactory, $options);
45+
46+
// Returns a cache plugin with the current default behavior
47+
$cachePlugin = CachePlugin::serverCache($pool, $streamFactory, $options);
48+
3649
Options
3750
-------
3851

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

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-
+---------------------------+---------------------+------------------------------------------------------+
54+
+---------------------------------------+----------------------------------------------------+-----------------------------------------------------------------------+
55+
| Name | Default value | Description |
56+
+=======================================+====================================================+=======================================================================+
57+
| ``default_ttl`` | ``0`` | The default max age of a Response |
58+
+---------------------------------------+----------------------------------------------------+-----------------------------------------------------------------------+
59+
| ``respect_cache_headers`` | ``true`` | Whether we should care about cache headers or not |
60+
| | | * This option is deprecated. Use `respect_response_cache_directives` |
61+
+---------------------------------------+----------------------------------------------------+-----------------------------------------------------------------------+
62+
| ``cache_lifetime`` | 30 days | The minimum time we should store a cache item |
63+
+---------------------------------------+----------------------------------------------------+-----------------------------------------------------------------------+
64+
| ``methods`` | ``['GET', 'HEAD']`` | Which request methods to cache |
65+
+---------------------------------------+----------------------------------------------------+-----------------------------------------------------------------------+
66+
| ``respect_response_cache_directives`` | ``['no-cache', 'private', 'max-age', 'no-store']`` | A list of cache directives to respect when caching responses |
67+
+---------------------------------------+----------------------------------------------------+-----------------------------------------------------------------------+
5268

5369
.. note::
5470

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

6985
$options = [
7086
'default_ttl' => 3600, // cache for one hour
71-
'respect_cache_headers' => false,
87+
'respect_response_cache_directives' => [],
7288
];
7389

7490
Semantics of null values
@@ -81,7 +97,7 @@ Store a response as long the cache implementation allows::
8197

8298
$options = [
8399
'default_ttl' => null,
84-
'respect_cache_headers' => false,
100+
'respect_response_cache_directives' => [],
85101
'cache_lifetime' => null,
86102
];
87103

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

91107
$options = [
92108
'default_ttl' => 3600,
93-
'respect_cache_headers' => false,
109+
'respect_response_cache_directives' => [],
94110
'cache_lifetime' => null,
95111
];
96112

@@ -100,7 +116,7 @@ removed from the cache::
100116

101117
$options = [
102118
'default_ttl' => 3600,
103-
'respect_cache_headers' => false,
119+
'respect_response_cache_directives' => [],
104120
'cache_lifetime' => 86400*365, // one year
105121
];
106122

@@ -125,7 +141,9 @@ to include them. You can specify any uppercase request method which conforms to
125141
Cache Control Handling
126142
----------------------
127143

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

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

0 commit comments

Comments
 (0)