Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,20 @@ passing an array of `$options` in the constructor:
**Type**: `int`
**Default**: `500`

* **purge_tags_header**: The HTTP header name used to check for tags
* **cache_tags_header**: The HTTP header name used to check for tags

**Type**: `string`
**Default**: `Cache-Tags`

### Cache Tagging

Tag cache entries by adding a response header with the tags as a comma
separated value. By default, that header is called `Cache-Tags`, this can be
overwritten in `cache_tags_header`.

To invalidate tags, call the method `Psr6Store::invalidateTags` or use the
`PurgeTagsListener` from the [FOSHttpCache][3] library to handle tag
invalidation requests.

### WARNING

Expand Down
16 changes: 9 additions & 7 deletions src/Psr6Store.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ final class Psr6Store implements StoreInterface
* Type: int
* Default: 500
*
* - purge_tags_header: The HTTP header name used to check for tags
* - cache_tags_header: Name of HTTP header containing a comma separated
* list of tags to tag the response with.
*
* Type: string
* Default: Cache-Tags
Expand All @@ -111,8 +112,8 @@ public function __construct(array $options = [])
$resolver->setDefault('prune_threshold', 500)
->setAllowedTypes('prune_threshold', 'int');

$resolver->setDefault('purge_tags_header', 'Cache-Tags')
->setAllowedTypes('purge_tags_header', 'string');
$resolver->setDefault('cache_tags_header', 'Cache-Tags')
->setAllowedTypes('cache_tags_header', 'string');

$resolver->setDefault('cache', function (Options $options) {
if (!isset($options['cache_directory'])) {
Expand Down Expand Up @@ -231,8 +232,8 @@ public function write(Request $request, Response $response)

// Tags
$tags = [];
if ($response->headers->has($this->options['purge_tags_header'])) {
$tags = explode(',', $response->headers->get($this->options['purge_tags_header']));
if ($response->headers->has($this->options['cache_tags_header'])) {
$tags = explode(',', $response->headers->get($this->options['cache_tags_header']));
}

// Prune expired entries on file system if needed
Expand Down Expand Up @@ -356,13 +357,14 @@ public function cleanup()

/**
* Remove/Expire cache objects based on cache tags.
* Returns true on success and false otherwise.
*
* The tags are set from the header configured in cache_tags_header.
*
* @param array $tags Tags that should be removed/expired from the cache
*
* @throws \RuntimeException if incompatible cache adapter provided
*
* @return bool
* @return bool true on success, false otherwise
*/
public function invalidateTags(array $tags)
{
Expand Down