@@ -33,22 +33,40 @@ control headers from the server as specified in :rfc:`7234`. It needs a
33
33
[$cachePlugin]
34
34
);
35
35
36
+
37
+ The ``CachePlugin `` has also 2 factory methods to easily setup the plugin by caching type. See the example below.
38
+
39
+ .. code-block :: php
40
+
41
+ // This will allows caching responses with the 'private' and/or 'no-store' cache directives
42
+ $cachePlugin = CachePlugin::clientCache($pool, $streamFactory, $options);
43
+
44
+ // Returns a cache plugin with the current default behavior
45
+ $cachePlugin = CachePlugin::serverCache($pool, $streamFactory, $options);
46
+
47
+ .. note ::
48
+
49
+ The two factory methods have been added in version 1.3.0.
50
+
36
51
Options
37
52
-------
38
53
39
54
The third parameter to the ``CachePlugin `` constructor takes an array of options. The available options are:
40
55
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
- +---------------------------+---------------------+------------------------------------------------------+
56
+ +---------------------------------------+----------------------------------------------------+-----------------------------------------------------------------------+
57
+ | Name | Default value | Description |
58
+ +=======================================+====================================================+=======================================================================+
59
+ | ``default_ttl `` | ``0 `` | The default max age of a Response |
60
+ +---------------------------------------+----------------------------------------------------+-----------------------------------------------------------------------+
61
+ | ``respect_cache_headers `` | ``true `` | Whether we should care about cache headers or not |
62
+ | | | * This option is deprecated. Use `respect_response_cache_directives ` |
63
+ +---------------------------------------+----------------------------------------------------+-----------------------------------------------------------------------+
64
+ | ``cache_lifetime `` | 30 days | The minimum time we should store a cache item |
65
+ +---------------------------------------+----------------------------------------------------+-----------------------------------------------------------------------+
66
+ | ``methods `` | ``['GET', 'HEAD'] `` | Which request methods to cache |
67
+ +---------------------------------------+----------------------------------------------------+-----------------------------------------------------------------------+
68
+ | ``respect_response_cache_directives `` | ``['no-cache', 'private', 'max-age', 'no-store'] `` | A list of cache directives to respect when caching responses |
69
+ +---------------------------------------+----------------------------------------------------+-----------------------------------------------------------------------+
52
70
53
71
.. note ::
54
72
@@ -68,7 +86,7 @@ for the default time to live. The options below will cache all responses for one
68
86
69
87
$options = [
70
88
'default_ttl' => 3600, // cache for one hour
71
- 'respect_cache_headers ' => false ,
89
+ 'respect_response_cache_directives ' => [] ,
72
90
];
73
91
74
92
Semantics of null values
@@ -81,7 +99,7 @@ Store a response as long the cache implementation allows::
81
99
82
100
$options = [
83
101
'default_ttl' => null,
84
- 'respect_cache_headers ' => false ,
102
+ 'respect_response_cache_directives ' => [] ,
85
103
'cache_lifetime' => null,
86
104
];
87
105
@@ -90,7 +108,7 @@ Ask the server if the response is valid at most ever hour. Store the cache item
90
108
91
109
$options = [
92
110
'default_ttl' => 3600,
93
- 'respect_cache_headers ' => false ,
111
+ 'respect_response_cache_directives ' => [] ,
94
112
'cache_lifetime' => null,
95
113
];
96
114
@@ -100,7 +118,7 @@ removed from the cache::
100
118
101
119
$options = [
102
120
'default_ttl' => 3600,
103
- 'respect_cache_headers ' => false ,
121
+ 'respect_response_cache_directives ' => [] ,
104
122
'cache_lifetime' => 86400*365, // one year
105
123
];
106
124
@@ -125,7 +143,9 @@ to include them. You can specify any uppercase request method which conforms to
125
143
Cache Control Handling
126
144
----------------------
127
145
128
- This plugin does not cache responses with ``no-store `` or ``private `` instructions.
146
+ By default this plugin does not cache responses with ``no-store ``, ``no-cache `` or ``private `` instructions. Use
147
+ ``CachePlugin::clientCache($pool, $streamFactory, $options); `` to cache ``no-store `` or ``private `` responses or change
148
+ the ``respect_response_cache_directives `` option to your needs.
129
149
130
150
It does store responses with cookies or a ``Set-Cookie `` header. Be careful with
131
151
the order of your plugins.
0 commit comments