From 8a4485612eb402824d450cce58f4e8b3a17e9ed6 Mon Sep 17 00:00:00 2001 From: Denis Ah-Kang Date: Tue, 3 Mar 2026 18:35:15 +0400 Subject: [PATCH 1/9] add suport for prefix invalidation --- doc/proxy-clients.rst | 20 ++++++------ src/CacheInvalidator.php | 15 +++++++++ src/ProxyClient/Cloudflare.php | 27 +++++++++++++++- .../Invalidation/PrefixCapable.php | 31 +++++++++++++++++++ tests/Unit/ProxyClient/CloudflareTest.php | 22 +++++++++++++ 5 files changed, 104 insertions(+), 11 deletions(-) create mode 100644 src/ProxyClient/Invalidation/PrefixCapable.php diff --git a/doc/proxy-clients.rst b/doc/proxy-clients.rst index 298f57e1..acd0b9ae 100644 --- a/doc/proxy-clients.rst +++ b/doc/proxy-clients.rst @@ -19,17 +19,17 @@ Supported invalidation methods Not all clients support all :ref:`invalidation methods `. This table provides of methods supported by each proxy client: -============= ======= ======= ======= ======= ======= -Client Purge Refresh Ban Tagging Clear -============= ======= ======= ======= ======= ======= +============= ======= ======= ======= ======= ====== ======= +Client Purge Refresh Ban Tagging Prefix Clear +============= ======= ======= ======= ======= ====== ======= Varnish ✓ ✓ ✓ ✓ -Fastly ✓ ✓ ✓ ✓ +Fastly ✓ ✓ ✓ ✓ NGINX ✓ ✓ -Symfony Cache ✓ ✓ ✓ (1) ✓ (1) -Cloudflare ✓ ✓ (2) ✓ -Noop ✓ ✓ ✓ ✓ ✓ -Multiplexer ✓ ✓ ✓ ✓ ✓ -============= ======= ======= ======= ======= ======= +Symfony Cache ✓ ✓ ✓ (1) ✓ (1) +Cloudflare ✓ ✓ (2) ✓ (2) ✓ +Noop ✓ ✓ ✓ ✓ ✓ +Multiplexer ✓ ✓ ✓ ✓ ✓ +============= ======= ======= ======= ======= ====== ======= | (1): Only when using `Toflar Psr6Store`_. | (2): Only available with `Cloudflare Enterprise`_. @@ -357,7 +357,7 @@ the HttpDispatcher is not available for Cloudflare):: Cloudflare supports different cache purge methods depending on your account. All Cloudflare accounts support purging the cache by URL and clearing all cache items. You need a `Cloudflare Enterprise`_ account to purge by cache - tags. + tags or prefixes. Zone identifier ^^^^^^^^^^^^^^^ diff --git a/src/CacheInvalidator.php b/src/CacheInvalidator.php index fe81a60d..86c38a8f 100644 --- a/src/CacheInvalidator.php +++ b/src/CacheInvalidator.php @@ -18,6 +18,7 @@ use FOS\HttpCache\Exception\UnsupportedProxyOperationException; use FOS\HttpCache\ProxyClient\Invalidation\BanCapable; use FOS\HttpCache\ProxyClient\Invalidation\ClearCapable; +use FOS\HttpCache\ProxyClient\Invalidation\PrefixCapable; use FOS\HttpCache\ProxyClient\Invalidation\PurgeCapable; use FOS\HttpCache\ProxyClient\Invalidation\RefreshCapable; use FOS\HttpCache\ProxyClient\Invalidation\TagCapable; @@ -216,6 +217,20 @@ public function invalidateTags(array $tags): static return $this; } + public function invalidatePrefixes(array $prefixes): static + { + if (!$this->cache instanceof PrefixCapable) { + throw UnsupportedProxyOperationException::cacheDoesNotImplement('Prefixes'); + } + if (!$prefixes) { + return $this; + } + + $this->cache->invalidatePrefixes($prefixes); + + return $this; + } + /** * Invalidate URLs based on a regular expression for the URI, an optional * content type and optional limit to certain hosts. diff --git a/src/ProxyClient/Cloudflare.php b/src/ProxyClient/Cloudflare.php index 785a7bf4..572acabb 100644 --- a/src/ProxyClient/Cloudflare.php +++ b/src/ProxyClient/Cloudflare.php @@ -12,6 +12,7 @@ namespace FOS\HttpCache\ProxyClient; use FOS\HttpCache\ProxyClient\Invalidation\ClearCapable; +use FOS\HttpCache\ProxyClient\Invalidation\PrefixCapable; use FOS\HttpCache\ProxyClient\Invalidation\PurgeCapable; use FOS\HttpCache\ProxyClient\Invalidation\TagCapable; use Psr\Http\Message\RequestFactoryInterface; @@ -27,7 +28,7 @@ * * @author Simon Jones */ -class Cloudflare extends HttpProxyClient implements ClearCapable, PurgeCapable, TagCapable +class Cloudflare extends HttpProxyClient implements ClearCapable, PrefixCapable, PurgeCapable, TagCapable { /** * @see https://api.cloudflare.com/#getting-started-endpoints @@ -87,6 +88,30 @@ public function invalidateTags(array $tags): static return $this; } + /** + * {@inheritdoc} + * + * URL prefix only available with Cloudflare enterprise plans + * + * @see https://developers.cloudflare.com/api/resources/cache/methods/purge/ + */ + public function invalidatePrefixes(array $prefixes): static + { + if (!$prefixes) { + return $this; + } + + $this->queueRequest( + 'POST', + sprintf(self::API_ENDPOINT.'/zones/%s/purge_cache', $this->options['zone_identifier']), + [], + false, + json_encode(['prefixes' => $prefixes], JSON_THROW_ON_ERROR | JSON_UNESCAPED_SLASHES) + ); + + return $this; + } + /** * @see https://api.cloudflare.com/#zone-purge-files-by-url * @see https://developers.cloudflare.com/cache/how-to/purge-cache#purge-by-single-file-by-url For details on headers you can pass to clear the cache correctly diff --git a/src/ProxyClient/Invalidation/PrefixCapable.php b/src/ProxyClient/Invalidation/PrefixCapable.php new file mode 100644 index 00000000..daefb8d8 --- /dev/null +++ b/src/ProxyClient/Invalidation/PrefixCapable.php @@ -0,0 +1,31 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace FOS\HttpCache\ProxyClient\Invalidation; + +use FOS\HttpCache\ProxyClient\ProxyClient; + +/** + * An HTTP cache that supports invalidation by a cache tag, that is, removing + * or expiring objects from the cache tagged with a given tag or set of tags. + * + * HTTP responses must carry the tags header name with the tags header value + * for tag invalidation to work. + */ +interface PrefixCapable extends ProxyClient +{ + /** + * Remove/Expire cache objects based on cache tags. + * + * @param string[] $tags Tags that should be removed/expired from the cache. An empty tag list should be ignored. + */ + public function invalidatePrefixes(array $prefixes): static; +} diff --git a/tests/Unit/ProxyClient/CloudflareTest.php b/tests/Unit/ProxyClient/CloudflareTest.php index a109c9bb..f834d023 100644 --- a/tests/Unit/ProxyClient/CloudflareTest.php +++ b/tests/Unit/ProxyClient/CloudflareTest.php @@ -71,6 +71,28 @@ function (RequestInterface $request) { $cloudflare->invalidateTags(['tag-one', 'tag-two']); } + public function testInvalidatePrefixesPurge(): void + { + $cloudflare = $this->getProxyClient(); + + $this->httpDispatcher->shouldReceive('invalidate')->once()->with( + \Mockery::on( + function (RequestInterface $request) { + $this->assertEquals('POST', $request->getMethod()); + $this->assertEquals('Bearer '.self::AUTH_TOKEN, current($request->getHeader('Authorization'))); + $this->assertEquals(sprintf('/client/v4/zones/%s/purge_cache', self::ZONE_IDENTIFIER), $request->getRequestTarget()); + + $this->assertEquals('{"prefixes":["example.com/one/","example.com/two/"]}', $request->getBody()->getContents()); + + return true; + } + ), + false + ); + + $cloudflare->invalidateTags(['example.com/one/', 'example.com/two/']); + } + public function testPurge(): void { $cloudflare = $this->getProxyClient(); From 8688eb90fbc12752e128d3f64abad6dcd647d59f Mon Sep 17 00:00:00 2001 From: Denis Ah-Kang Date: Wed, 4 Mar 2026 09:10:47 +0400 Subject: [PATCH 2/9] fix doc --- src/ProxyClient/Invalidation/PrefixCapable.php | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/ProxyClient/Invalidation/PrefixCapable.php b/src/ProxyClient/Invalidation/PrefixCapable.php index daefb8d8..09adc1fe 100644 --- a/src/ProxyClient/Invalidation/PrefixCapable.php +++ b/src/ProxyClient/Invalidation/PrefixCapable.php @@ -14,18 +14,15 @@ use FOS\HttpCache\ProxyClient\ProxyClient; /** - * An HTTP cache that supports invalidation by a cache tag, that is, removing - * or expiring objects from the cache tagged with a given tag or set of tags. - * - * HTTP responses must carry the tags header name with the tags header value - * for tag invalidation to work. + * An HTTP cache that supports invalidation by a prefix, that is, removing + * or expiring objects from the cache with a given prefix or set of prefixes. */ interface PrefixCapable extends ProxyClient { /** - * Remove/Expire cache objects based on cache tags. + * Remove/Expire cache objects based on URL prefixes. * - * @param string[] $tags Tags that should be removed/expired from the cache. An empty tag list should be ignored. + * @param string[] $prefixes Prefixed objects that should be removed/expired from the cache. An empty prefix list should be ignored. */ public function invalidatePrefixes(array $prefixes): static; } From 106f2a333a6f72f1073763f8498b114109cb9bbc Mon Sep 17 00:00:00 2001 From: Denis Ah-Kang Date: Wed, 4 Mar 2026 09:15:59 +0400 Subject: [PATCH 3/9] fix test --- tests/Unit/ProxyClient/CloudflareTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Unit/ProxyClient/CloudflareTest.php b/tests/Unit/ProxyClient/CloudflareTest.php index f834d023..10c3dff3 100644 --- a/tests/Unit/ProxyClient/CloudflareTest.php +++ b/tests/Unit/ProxyClient/CloudflareTest.php @@ -90,7 +90,7 @@ function (RequestInterface $request) { false ); - $cloudflare->invalidateTags(['example.com/one/', 'example.com/two/']); + $cloudflare->invalidatePrefixes(['example.com/one/', 'example.com/two/']); } public function testPurge(): void From 2c6c25dca2f23eb1ee2ea0223484034691422852 Mon Sep 17 00:00:00 2001 From: Denis Ah-Kang <1696128+deniak@users.noreply.github.com> Date: Wed, 4 Mar 2026 15:29:24 +0400 Subject: [PATCH 4/9] Apply suggestions from code review Co-authored-by: David Buchmann --- src/ProxyClient/Cloudflare.php | 4 +++- src/ProxyClient/Invalidation/PrefixCapable.php | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/ProxyClient/Cloudflare.php b/src/ProxyClient/Cloudflare.php index 572acabb..d1471548 100644 --- a/src/ProxyClient/Cloudflare.php +++ b/src/ProxyClient/Cloudflare.php @@ -91,7 +91,9 @@ public function invalidateTags(array $tags): static /** * {@inheritdoc} * - * URL prefix only available with Cloudflare enterprise plans + * URL prefix only available with Cloudflare enterprise plans. + * + * The prefixes need to include the domain name, but not the protocol, e.g. "www.example.com/path" * * @see https://developers.cloudflare.com/api/resources/cache/methods/purge/ */ diff --git a/src/ProxyClient/Invalidation/PrefixCapable.php b/src/ProxyClient/Invalidation/PrefixCapable.php index 09adc1fe..2758726e 100644 --- a/src/ProxyClient/Invalidation/PrefixCapable.php +++ b/src/ProxyClient/Invalidation/PrefixCapable.php @@ -15,7 +15,7 @@ /** * An HTTP cache that supports invalidation by a prefix, that is, removing - * or expiring objects from the cache with a given prefix or set of prefixes. + * or expiring objects from the cache starting with the given string or strings. */ interface PrefixCapable extends ProxyClient { From 105528681142dbf3d895ee2bbe39ebc465d2bf49 Mon Sep 17 00:00:00 2001 From: Denis Ah-Kang Date: Wed, 4 Mar 2026 15:28:47 +0400 Subject: [PATCH 5/9] Multiplexer and Noop clients should also implement PrefixCapable --- doc/proxy-clients.rst | 4 ++-- src/ProxyClient/MultiplexerClient.php | 18 +++++++++++++++++- src/ProxyClient/Noop.php | 8 +++++++- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/doc/proxy-clients.rst b/doc/proxy-clients.rst index acd0b9ae..0f2b2345 100644 --- a/doc/proxy-clients.rst +++ b/doc/proxy-clients.rst @@ -27,8 +27,8 @@ Fastly ✓ ✓ ✓ ✓ NGINX ✓ ✓ Symfony Cache ✓ ✓ ✓ (1) ✓ (1) Cloudflare ✓ ✓ (2) ✓ (2) ✓ -Noop ✓ ✓ ✓ ✓ ✓ -Multiplexer ✓ ✓ ✓ ✓ ✓ +Noop ✓ ✓ ✓ ✓ ✓ ✓ +Multiplexer ✓ ✓ ✓ ✓ ✓ ✓ ============= ======= ======= ======= ======= ====== ======= | (1): Only when using `Toflar Psr6Store`_. diff --git a/src/ProxyClient/MultiplexerClient.php b/src/ProxyClient/MultiplexerClient.php index a7caaedb..78faff0f 100644 --- a/src/ProxyClient/MultiplexerClient.php +++ b/src/ProxyClient/MultiplexerClient.php @@ -14,6 +14,7 @@ use FOS\HttpCache\Exception\InvalidArgumentException; use FOS\HttpCache\ProxyClient\Invalidation\BanCapable; use FOS\HttpCache\ProxyClient\Invalidation\ClearCapable; +use FOS\HttpCache\ProxyClient\Invalidation\PrefixCapable; use FOS\HttpCache\ProxyClient\Invalidation\PurgeCapable; use FOS\HttpCache\ProxyClient\Invalidation\RefreshCapable; use FOS\HttpCache\ProxyClient\Invalidation\TagCapable; @@ -23,7 +24,7 @@ * * @author Emanuele Panzeri */ -class MultiplexerClient implements BanCapable, PurgeCapable, RefreshCapable, TagCapable, ClearCapable +class MultiplexerClient implements BanCapable, PrefixCapable, PurgeCapable, RefreshCapable, TagCapable, ClearCapable { /** * @var ProxyClient[] @@ -93,6 +94,21 @@ public function invalidateTags(array $tags): static return $this; } + /** + * Forwards prefix invalidation request to all clients. + * + * {@inheritdoc} + */ + public function invalidatePrefixes(array $prefixes): static + { + if (!$prefixes) { + return $this; + } + $this->invoke(PrefixCapable::class, 'invalidatePrefixes', [$prefixes]); + + return $this; + } + /** * Forwards to all clients. * diff --git a/src/ProxyClient/Noop.php b/src/ProxyClient/Noop.php index 904b7c4b..93b09fa8 100644 --- a/src/ProxyClient/Noop.php +++ b/src/ProxyClient/Noop.php @@ -13,6 +13,7 @@ use FOS\HttpCache\ProxyClient\Invalidation\BanCapable; use FOS\HttpCache\ProxyClient\Invalidation\ClearCapable; +use FOS\HttpCache\ProxyClient\Invalidation\PrefixCapable; use FOS\HttpCache\ProxyClient\Invalidation\PurgeCapable; use FOS\HttpCache\ProxyClient\Invalidation\RefreshCapable; use FOS\HttpCache\ProxyClient\Invalidation\TagCapable; @@ -26,7 +27,7 @@ * * @author Gavin Staniforth */ -class Noop implements ProxyClient, BanCapable, PurgeCapable, RefreshCapable, TagCapable, ClearCapable +class Noop implements ProxyClient, BanCapable, PrefixCapable, PurgeCapable, RefreshCapable, TagCapable, ClearCapable { public function ban(array $headers): static { @@ -43,6 +44,11 @@ public function invalidateTags(array $tags): static return $this; } + public function invalidatePrefixes(array $prefixes): static + { + return $this; + } + public function purge(string $url, array $headers = []): static { return $this; From 007314c3959f597a8bf91a7144434ab05b2f3f90 Mon Sep 17 00:00:00 2001 From: Denis Ah-Kang Date: Wed, 4 Mar 2026 15:40:10 +0400 Subject: [PATCH 6/9] update varnish client to also support prefix using banPath --- doc/proxy-clients.rst | 2 +- src/ProxyClient/Varnish.php | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/doc/proxy-clients.rst b/doc/proxy-clients.rst index 0f2b2345..3cfb3ff7 100644 --- a/doc/proxy-clients.rst +++ b/doc/proxy-clients.rst @@ -22,7 +22,7 @@ This table provides of methods supported by each proxy client: ============= ======= ======= ======= ======= ====== ======= Client Purge Refresh Ban Tagging Prefix Clear ============= ======= ======= ======= ======= ====== ======= -Varnish ✓ ✓ ✓ ✓ +Varnish ✓ ✓ ✓ ✓ ✓ Fastly ✓ ✓ ✓ ✓ NGINX ✓ ✓ Symfony Cache ✓ ✓ ✓ (1) ✓ (1) diff --git a/src/ProxyClient/Varnish.php b/src/ProxyClient/Varnish.php index 6f7c6b02..68820ac4 100644 --- a/src/ProxyClient/Varnish.php +++ b/src/ProxyClient/Varnish.php @@ -13,6 +13,7 @@ use FOS\HttpCache\Exception\InvalidArgumentException; use FOS\HttpCache\ProxyClient\Invalidation\BanCapable; +use FOS\HttpCache\ProxyClient\Invalidation\PrefixCapable; use FOS\HttpCache\ProxyClient\Invalidation\PurgeCapable; use FOS\HttpCache\ProxyClient\Invalidation\RefreshCapable; use FOS\HttpCache\ProxyClient\Invalidation\TagCapable; @@ -36,7 +37,7 @@ * * @author David de Boer */ -class Varnish extends HttpProxyClient implements BanCapable, PurgeCapable, RefreshCapable, TagCapable +class Varnish extends HttpProxyClient implements BanCapable, PrefixCapable, PurgeCapable, RefreshCapable, TagCapable { public const HTTP_METHOD_BAN = 'BAN'; @@ -127,6 +128,22 @@ public function banPath(string $path, ?string $contentType = null, array|string| return $this->ban($headers); } + public function invalidatePrefixes(array $prefixes): static + { + if (!$prefixes) { + return $this; + } + + foreach ($prefixes as $prefix) { + $parts = explode('/', $prefix, 2); + $host = $parts[0]; + $path = isset($parts[1]) ? '/'.$parts[1] : '/'; + $this->banPath($path, null, $host); + } + + return $this; + } + public function purge(string $url, array $headers = []): static { $this->queueRequest(self::HTTP_METHOD_PURGE, $url, $headers); From 134beffd0c7465ab34ba791618facce4e29ddf34 Mon Sep 17 00:00:00 2001 From: Denis Ah-Kang Date: Wed, 4 Mar 2026 15:41:59 +0400 Subject: [PATCH 7/9] php-cs --- src/ProxyClient/Cloudflare.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ProxyClient/Cloudflare.php b/src/ProxyClient/Cloudflare.php index d1471548..c9101568 100644 --- a/src/ProxyClient/Cloudflare.php +++ b/src/ProxyClient/Cloudflare.php @@ -92,7 +92,7 @@ public function invalidateTags(array $tags): static * {@inheritdoc} * * URL prefix only available with Cloudflare enterprise plans. - * + * * The prefixes need to include the domain name, but not the protocol, e.g. "www.example.com/path" * * @see https://developers.cloudflare.com/api/resources/cache/methods/purge/ From 1490d8e2d5afda258282979e04c3a09a47f91cdf Mon Sep 17 00:00:00 2001 From: Denis Ah-Kang Date: Wed, 4 Mar 2026 19:37:11 +0400 Subject: [PATCH 8/9] add note for the prefix method --- doc/proxy-clients.rst | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/doc/proxy-clients.rst b/doc/proxy-clients.rst index 3cfb3ff7..e21e0b5a 100644 --- a/doc/proxy-clients.rst +++ b/doc/proxy-clients.rst @@ -19,18 +19,19 @@ Supported invalidation methods Not all clients support all :ref:`invalidation methods `. This table provides of methods supported by each proxy client: -============= ======= ======= ======= ======= ====== ======= -Client Purge Refresh Ban Tagging Prefix Clear -============= ======= ======= ======= ======= ====== ======= +============= ======= ======= ======= ======= ========= ======= +Client Purge Refresh Ban Tagging Prefix(*) Clear +============= ======= ======= ======= ======= ========= ======= Varnish ✓ ✓ ✓ ✓ ✓ -Fastly ✓ ✓ ✓ ✓ +Fastly ✓ ✓ ✓ ✓ NGINX ✓ ✓ -Symfony Cache ✓ ✓ ✓ (1) ✓ (1) -Cloudflare ✓ ✓ (2) ✓ (2) ✓ -Noop ✓ ✓ ✓ ✓ ✓ ✓ -Multiplexer ✓ ✓ ✓ ✓ ✓ ✓ -============= ======= ======= ======= ======= ====== ======= +Symfony Cache ✓ ✓ ✓ (1) ✓ (1) +Cloudflare ✓ ✓ (2) ✓ (2) ✓ +Noop ✓ ✓ ✓ ✓ ✓ ✓ +Multiplexer ✓ ✓ ✓ ✓ ✓ ✓ +============= ======= ======= ======= ======= ========= ======= +| (*): A limited version of Ban, that allows to invalidate by the beginning of a path | (1): Only when using `Toflar Psr6Store`_. | (2): Only available with `Cloudflare Enterprise`_. From e3d97dbbe87aa859e5fa094cb9ff3d88bfa80fc8 Mon Sep 17 00:00:00 2001 From: Denis Ah-Kang Date: Wed, 4 Mar 2026 19:49:53 +0400 Subject: [PATCH 9/9] add tests for invalidatePrefixes --- .../ProxyClient/MultiplexerClientTest.php | 16 ++++++++++++++++ tests/Unit/ProxyClient/NoopTest.php | 5 +++++ tests/Unit/ProxyClient/VarnishTest.php | 19 +++++++++++++++++++ 3 files changed, 40 insertions(+) diff --git a/tests/Unit/ProxyClient/MultiplexerClientTest.php b/tests/Unit/ProxyClient/MultiplexerClientTest.php index c88e966d..362f6502 100644 --- a/tests/Unit/ProxyClient/MultiplexerClientTest.php +++ b/tests/Unit/ProxyClient/MultiplexerClientTest.php @@ -14,6 +14,7 @@ use FOS\HttpCache\Exception\InvalidArgumentException; use FOS\HttpCache\ProxyClient\Invalidation\BanCapable; use FOS\HttpCache\ProxyClient\Invalidation\ClearCapable; +use FOS\HttpCache\ProxyClient\Invalidation\PrefixCapable; use FOS\HttpCache\ProxyClient\Invalidation\PurgeCapable; use FOS\HttpCache\ProxyClient\Invalidation\RefreshCapable; use FOS\HttpCache\ProxyClient\Invalidation\TagCapable; @@ -103,6 +104,21 @@ public function testInvalidateTags(): void $this->assertSame($multiplexer, $multiplexer->invalidateTags($tags)); } + public function testInvalidatePrefixes(): void + { + $prefixes = ['example.com/one/', 'example.com/two/']; + + $mockClient = \Mockery::mock(PrefixCapable::class) + ->shouldReceive('invalidatePrefixes') + ->once() + ->with($prefixes) + ->getMock(); + + $multiplexer = new MultiplexerClient([$mockClient]); + + $this->assertSame($multiplexer, $multiplexer->invalidatePrefixes($prefixes)); + } + public function testRefresh(): void { $url = 'example.com'; diff --git a/tests/Unit/ProxyClient/NoopTest.php b/tests/Unit/ProxyClient/NoopTest.php index 878c2fdc..f29512b7 100644 --- a/tests/Unit/ProxyClient/NoopTest.php +++ b/tests/Unit/ProxyClient/NoopTest.php @@ -33,6 +33,11 @@ public function testInvalidateTags(): void $this->assertSame($this->noop, $this->noop->invalidateTags(['tag123'])); } + public function testInvalidatePrefixes(): void + { + $this->assertSame($this->noop, $this->noop->invalidatePrefixes(['example.com/one/'])); + } + public function testBanPath(): void { $this->assertSame($this->noop, $this->noop->banPath('/123')); diff --git a/tests/Unit/ProxyClient/VarnishTest.php b/tests/Unit/ProxyClient/VarnishTest.php index 7dde033d..f7894d81 100644 --- a/tests/Unit/ProxyClient/VarnishTest.php +++ b/tests/Unit/ProxyClient/VarnishTest.php @@ -236,4 +236,23 @@ function (RequestInterface $request) { $varnish->refresh('/fresh'); } + + public function testInvalidatePrefixes(): void + { + $varnish = new Varnish($this->httpDispatcher); + $this->httpDispatcher->shouldReceive('invalidate')->once()->with( + \Mockery::on( + function (RequestInterface $request) { + $this->assertEquals('BAN', $request->getMethod()); + $this->assertEquals('example.org', $request->getHeaderLine('X-Host')); + $this->assertEquals('/one/', $request->getHeaderLine('X-Url')); + $this->assertEquals('.*', $request->getHeaderLine('X-Content-Type')); + + return true; + } + ), + false + ); + $varnish->invalidatePrefixes(['example.org/one/']); + } }