Skip to content

Commit

Permalink
Revert the Cache-Tag cloudflare invalidation to the Cache-Tags
Browse files Browse the repository at this point in the history
  • Loading branch information
darkweak committed Dec 15, 2021
1 parent 96ec028 commit c2d7378
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 18 deletions.
20 changes: 10 additions & 10 deletions features/http_cache/tags.feature
Expand Up @@ -17,15 +17,15 @@ Feature: Cache invalidation through HTTP Cache tags
}
"""
Then the response status code should be 201
And the header "Cache-Tag" should not exist
And the header "Cache-Tags" should not exist
And the header "xkey" should not exist
And "/relation_embedders,/related_dummies,/third_levels" IRIs should be purged
And "/relation_embedders /related_dummies /third_levels" IRIs should be purged with xkey

Scenario: Tags must be set for items
When I send a "GET" request to "/relation_embedders/1"
Then the response status code should be 200
And the header "Cache-Tag" should be equal to "/relation_embedders/1,/related_dummies/1,/third_levels/1"
And the header "Cache-Tags" should be equal to "/relation_embedders/1,/related_dummies/1,/third_levels/1"
And the header "xkey" should be equal to "/relation_embedders/1 /related_dummies/1 /third_levels/1"

Scenario: Create some more resources
Expand All @@ -40,13 +40,13 @@ Feature: Cache invalidation through HTTP Cache tags
}
"""
Then the response status code should be 201
And the header "Cache-Tag" should not exist
And the header "Cache-Tags" should not exist
And the header "xkey" should not exist

Scenario: Tags must be set for collections
When I send a "GET" request to "/relation_embedders"
Then the response status code should be 200
And the header "Cache-Tag" should be equal to "/relation_embedders/1,/related_dummies/1,/third_levels/1,/relation_embedders/2,/related_dummies/2,/third_levels/2,/relation_embedders"
And the header "Cache-Tags" should be equal to "/relation_embedders/1,/related_dummies/1,/third_levels/1,/relation_embedders/2,/related_dummies/2,/third_levels/2,/relation_embedders"
And the header "xkey" should be equal to "/relation_embedders/1 /related_dummies/1 /third_levels/1 /relation_embedders/2 /related_dummies/2 /third_levels/2 /relation_embedders"

Scenario: Purge item on update
Expand All @@ -58,7 +58,7 @@ Feature: Cache invalidation through HTTP Cache tags
}
"""
Then the response status code should be 200
And the header "Cache-Tag" should not exist
And the header "Cache-Tags" should not exist
And the header "xkey" should not exist
And "/relation_embedders,/relation_embedders/1,/related_dummies/1" IRIs should be purged
And "/relation_embedders /relation_embedders/1 /related_dummies/1" IRIs should be purged with xkey
Expand All @@ -67,7 +67,7 @@ Feature: Cache invalidation through HTTP Cache tags
When I add "Content-Type" header equal to "application/ld+json"
And I send a "DELETE" request to "/relation_embedders/1"
Then the response status code should be 204
And the header "Cache-Tag" should not exist
And the header "Cache-Tags" should not exist
And the header "xkey" should not exist
And "/relation_embedders,/relation_embedders/1,/related_dummies/1" IRIs should be purged
And "/relation_embedders /relation_embedders/1 /related_dummies/1" IRIs should be purged with xkey
Expand All @@ -89,7 +89,7 @@ Feature: Cache invalidation through HTTP Cache tags

Scenario: Embedded collection must be listed in cache tags
When I send a "GET" request to "/relation2s/1"
Then the header "Cache-Tag" should be equal to "/relation2s/1"
Then the header "Cache-Tags" should be equal to "/relation2s/1"
Then the header "xkey" should be equal to "/relation2s/1"

Scenario: Create a Relation1
Expand Down Expand Up @@ -132,7 +132,7 @@ Feature: Cache invalidation through HTTP Cache tags
When I add "Content-Type" header equal to "application/ld+json"
And I send a "GET" request to "/relation3s"
Then the response status code should be 200
And the header "Cache-Tag" should be equal to "/relation3s/1,/relation2s/1,/relation2s/2,/relation3s"
And the header "Cache-Tags" should be equal to "/relation3s/1,/relation2s/1,/relation2s/2,/relation3s"
And the header "xkey" should be equal to "/relation3s/1 /relation2s/1 /relation2s/2 /relation3s"

Scenario: Update a collection member only
Expand All @@ -144,7 +144,7 @@ Feature: Cache invalidation through HTTP Cache tags
}
"""
Then the response status code should be 200
And the header "Cache-Tag" should not exist
And the header "Cache-Tags" should not exist
And the header "xkey" should not exist
And "/relation3s,/relation3s/1,/relation2s/2,/relation2s,/relation2s/1" IRIs should be purged
And "/relation3s /relation3s/1 /relation2s/2 /relation2s /relation2s/1" IRIs should be purged with xkey
Expand All @@ -153,7 +153,7 @@ Feature: Cache invalidation through HTTP Cache tags
When I add "Content-Type" header equal to "application/ld+json"
And I send a "DELETE" request to "/relation3s/1"
Then the response status code should be 204
And the header "Cache-Tag" should not exist
And the header "Cache-Tags" should not exist
And the header "xkey" should not exist
And "/relation3s,/relation3s/1,/relation2s/2" IRIs should be purged
And "/relation3s /relation3s/1 /relation2s/2" IRIs should be purged with xkey
4 changes: 2 additions & 2 deletions src/HttpCache/EventListener/AddTagsListener.php
Expand Up @@ -24,7 +24,7 @@
/**
* Sets the list of resources' IRIs included in this response in the configured cache tag HTTP header and/or "xkey" HTTP headers.
*
* By default the "Cache-Tag" HTTP header is used because it is supported by CloudFlare.
* By default the "Cache-Tags" HTTP header is used because it is supported by CloudFlare.
*
* @see https://developers.cloudflare.com/cache/how-to/purge-cache#add-cache-tag-http-response-headers
*
Expand All @@ -47,7 +47,7 @@ final class AddTagsListener
private $header;
private $separator;

public function __construct(IriConverterInterface $iriConverter, ResourceMetadataCollectionFactoryInterface $resourceMetadataCollectionFactory = null, bool $xkeyEnabled = false, string $xkeyGlue = ' ', bool $httpTagsEnabled = true, string $header = 'Cache-Tag', string $separator = ',')
public function __construct(IriConverterInterface $iriConverter, ResourceMetadataCollectionFactoryInterface $resourceMetadataCollectionFactory = null, bool $xkeyEnabled = false, string $xkeyGlue = ' ', bool $httpTagsEnabled = true, string $header = 'Cache-Tags', string $separator = ',')
{
$this->iriConverter = $iriConverter;
$this->resourceMetadataCollectionFactory = $resourceMetadataCollectionFactory;
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Bundle/DependencyInjection/Configuration.php
Expand Up @@ -424,7 +424,7 @@ private function addHttpCacheSection(ArrayNodeDefinition $rootNode): void
->end()
->arrayNode('http_tags')
->canBeDisabled()
->info('Enable support for Cache-Tag invalidation.')
->info('Enable support for Cache-Tags invalidation.')
->end()
->arrayNode('purger')
->addDefaultsIfNotSet()
Expand Down Expand Up @@ -455,7 +455,7 @@ private function addHttpCacheSection(ArrayNodeDefinition $rootNode): void
->info('Enable the tags-based cache validation system.')
->children()
->scalarNode('header')
->defaultValue('Cache-Tag')
->defaultValue('Cache-Tags')
->info('HTTP header to use to return the associated tags')
->end()
->scalarNode('separator')
Expand Down
4 changes: 2 additions & 2 deletions tests/HttpCache/EventListener/AddTagsListenerTest.php
Expand Up @@ -37,7 +37,7 @@ class AddTagsListenerTest extends TestCase
{
use ProphecyTrait;

public const DEFAULT_CACHE_TAG = 'Cache-Tag';
public const DEFAULT_CACHE_TAG = 'Cache-Tags';

public function testDoNotSetHeaderWhenMethodNotCacheable()
{
Expand Down Expand Up @@ -142,7 +142,7 @@ public function testAddTags()
$listener = new AddTagsListener($iriConverterProphecy->reveal());
$listener->onKernelResponse($event);

$this->assertSame('/foo,/bar', $response->headers->get('Cache-Tag'));
$this->assertSame('/foo,/bar', $response->headers->get('Cache-Tags'));
}

public function testAddCollectionIri()
Expand Down
Expand Up @@ -1096,7 +1096,7 @@ private function getPartialContainerBuilderProphecy($configuration = null)
'api_platform.enable_entrypoint' => true,
'api_platform.enable_docs' => true,
'api_platform.url_generation_strategy' => 1,
'api_platform.http_cache.validation.header' => 'Cache-Tag',
'api_platform.http_cache.validation.header' => 'Cache-Tags',
'api_platform.http_cache.validation.separator' => ',',
];

Expand Down
Expand Up @@ -208,7 +208,7 @@ private function runDefaultConfigTests(array $doctrineIntegrationsToLoad = ['orm
'vary' => ['Accept'],
'public' => null,
'validation' => [
'header' => 'Cache-Tag',
'header' => 'Cache-Tags',
'separator' => ',',
],
],
Expand Down

0 comments on commit c2d7378

Please sign in to comment.