From 4a71c00034f0b3def02eee5de0728bb048b627bf Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Wed, 27 Sep 2017 17:27:31 +0200 Subject: [PATCH] rename purge_tags_header config to cache_tags_header --- README.md | 11 ++++++++++- src/Psr6Store.php | 16 +++++++++------- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 6c88c30..3984034 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/Psr6Store.php b/src/Psr6Store.php index b7168ee..37af48a 100644 --- a/src/Psr6Store.php +++ b/src/Psr6Store.php @@ -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 @@ -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'])) { @@ -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 @@ -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) {