-
Notifications
You must be signed in to change notification settings - Fork 56
document cache plugin #86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,50 @@ | ||
Cache Plugin | ||
============ | ||
|
||
TODO | ||
The ``CachePlugin`` allows you to cache responses from the server. It can use | ||
any PSR-6 compatible caching engine. By default, the plugin respects the cache | ||
control headers from the server as specified in :rfc:`7234`. It needs a | ||
:ref:`stream <stream-factory>` and a `PSR-6`_ implementation:: | ||
|
||
use Http\Discovery\HttpClientDiscovery; | ||
use Http\Client\Plugin\PluginClient; | ||
use Http\Client\Plugin\CachePlugin; | ||
|
||
/** @var \Psr\Cache\CacheItemPoolInterface $pool */ | ||
$pool... | ||
/** @var \Http\Message\StreamFactory $streamFactory */ | ||
$streamFactory... | ||
|
||
$options = []; | ||
$cachePlugin = new CachePlugin($pool, $streamFactory, $options); | ||
|
||
$pluginClient = new PluginClient( | ||
HttpClientDiscovery::find(), | ||
[$cachePlugin] | ||
); | ||
|
||
By default, responses with no cache control headers are not cached. If you want | ||
a default cache lifetime if the server specifies no ``max-age``, use:: | ||
|
||
$options = [ | ||
'default_ttl' => 42, // cache lifetime time in seconds | ||
]; | ||
|
||
You can also tell the plugin to completely ignore the cache control headers | ||
from the server and force caching for the default time to life. Note that in | ||
this case, ``default_ttl`` is required:: | ||
|
||
$options = [ | ||
'default_ttl' => 3600, // cache for one hour | ||
'respect_cache_headers' => false, | ||
]; | ||
|
||
Cache Control Handling | ||
---------------------- | ||
|
||
This plugin does not cache responses with ``no-store`` or ``private`` instructions. | ||
|
||
It does store responses with cookies or a ``Set-Cookie`` header. Be careful with | ||
the order of your plugins. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Nyholm i created a bunch of issues on the plugin repo with things i noticed (some are simply new features, but some could be problematic). i did not create one for the cookie topic. i am not sure about this one. on a proxy, you never cache if there are Authorization or Cookie headers around, for fear of mixing up content. for a client this is less clear, depends on the scenario. might require another option on the plugin? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added to php-http/plugins#58 , i think splitting that plugin into two for the different roles makes more and more sense. |
||
|
||
.. _PSR-6: http://www.php-fig.org/psr/psr-6/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
feel like we should also respect
no-cache
. php-http/plugins#58