Skip to content

Commit 500f1d6

Browse files
committed
Docs for new cache plugin option
1 parent 395e79c commit 500f1d6

File tree

1 file changed

+29
-16
lines changed

1 file changed

+29
-16
lines changed

plugins/cache.rst

+29-16
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,33 @@ 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+
$cachePlugin = CachePlugin::clientCache($pool, $streamFactory, $options); // Which allows caching responses with the ``private`` or ``no-store`` cache directive
42+
$cachePlugin = CachePlugin::serverCache($pool, $streamFactory, $options); // Returns a cache plugin with the current default behavior
43+
3644
Options
3745
-------
3846

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

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

5364
.. note::
5465

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

6980
$options = [
7081
'default_ttl' => 3600, // cache for one hour
71-
'respect_cache_headers' => false,
82+
'respect_response_cache_directives' => [],
7283
];
7384

7485
Semantics of null values
@@ -81,7 +92,7 @@ Store a response as long the cache implementation allows::
8192

8293
$options = [
8394
'default_ttl' => null,
84-
'respect_cache_headers' => false,
95+
'respect_response_cache_directives' => [],
8596
'cache_lifetime' => null,
8697
];
8798

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

91102
$options = [
92103
'default_ttl' => 3600,
93-
'respect_cache_headers' => false,
104+
'respect_response_cache_directives' => [],
94105
'cache_lifetime' => null,
95106
];
96107

@@ -100,7 +111,7 @@ removed from the cache::
100111

101112
$options = [
102113
'default_ttl' => 3600,
103-
'respect_cache_headers' => false,
114+
'respect_response_cache_directives' => [],
104115
'cache_lifetime' => 86400*365, // one year
105116
];
106117

@@ -125,7 +136,9 @@ to include them. You can specify any uppercase request method which conforms to
125136
Cache Control Handling
126137
----------------------
127138

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

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

0 commit comments

Comments
 (0)