Skip to content

Commit

Permalink
Docs for new cache plugin option
Browse files Browse the repository at this point in the history
  • Loading branch information
acrobat committed Feb 27, 2017
1 parent 395e79c commit 663fdb4
Showing 1 changed file with 34 additions and 16 deletions.
50 changes: 34 additions & 16 deletions plugins/cache.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,38 @@ control headers from the server as specified in :rfc:`7234`. It needs a
[$cachePlugin]
);

.. note::

Since v1.3.0 does the ``CachePlugin`` have 2 factory methods to easily setup the plugin by caching type. See the
example below.

.. code-block:: php
// This will allows caching responses with the 'private' and/or 'no-store' cache directives
$cachePlugin = CachePlugin::clientCache($pool, $streamFactory, $options);
// Returns a cache plugin with the current default behavior
$cachePlugin = CachePlugin::serverCache($pool, $streamFactory, $options);
Options
-------

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

+---------------------------+---------------------+------------------------------------------------------+
| Name | Default value | Description |
+===========================+=====================+======================================================+
| ``default_ttl`` | ``0`` | The default max age of a Response |
+---------------------------+---------------------+------------------------------------------------------+
| ``respect_cache_headers`` | ``true`` | Whether we should care about cache headers or not |
+---------------------------+---------------------+------------------------------------------------------+
| ``cache_lifetime`` | 30 days | The minimum time we should store a cache item |
+---------------------------+---------------------+------------------------------------------------------+
| ``methods`` | ``['GET', 'HEAD']`` | Which request methods to cache |
+---------------------------+---------------------+------------------------------------------------------+
+---------------------------------------+----------------------------------------------------+-----------------------------------------------------------------------+
| Name | Default value | Description |
+=======================================+====================================================+=======================================================================+
| ``default_ttl`` | ``0`` | The default max age of a Response |
+---------------------------------------+----------------------------------------------------+-----------------------------------------------------------------------+
| ``respect_cache_headers`` | ``true`` | Whether we should care about cache headers or not |
| | | * This option is deprecated. Use `respect_response_cache_directives` |
+---------------------------------------+----------------------------------------------------+-----------------------------------------------------------------------+
| ``cache_lifetime`` | 30 days | The minimum time we should store a cache item |
+---------------------------------------+----------------------------------------------------+-----------------------------------------------------------------------+
| ``methods`` | ``['GET', 'HEAD']`` | Which request methods to cache |
+---------------------------------------+----------------------------------------------------+-----------------------------------------------------------------------+
| ``respect_response_cache_directives`` | ``['no-cache', 'private', 'max-age', 'no-store']`` | A list of cache directives to respect when caching responses |
+---------------------------------------+----------------------------------------------------+-----------------------------------------------------------------------+

.. note::

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

$options = [
'default_ttl' => 3600, // cache for one hour
'respect_cache_headers' => false,
'respect_response_cache_directives' => [],
];

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

$options = [
'default_ttl' => null,
'respect_cache_headers' => false,
'respect_response_cache_directives' => [],
'cache_lifetime' => null,
];

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

$options = [
'default_ttl' => 3600,
'respect_cache_headers' => false,
'respect_response_cache_directives' => [],
'cache_lifetime' => null,
];

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

$options = [
'default_ttl' => 3600,
'respect_cache_headers' => false,
'respect_response_cache_directives' => [],
'cache_lifetime' => 86400*365, // one year
];

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

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

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

0 comments on commit 663fdb4

Please sign in to comment.