-
-
Notifications
You must be signed in to change notification settings - Fork 928
feat(serializer): collect cache tags using a TagCollector #5758
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
74f1259
feat(serializer): collect cache tags using a TagCollector
usu 6550208
simplify function signature
usu c80a479
fix bug in JsonApi normalizer
usu 828ecb6
minor changes as per latest review
usu 2e2c2c2
disable new tests for Symfony lowest
usu 1be617d
cs
soyuka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
@sqlite | ||
@customTagCollector | ||
@disableForSymfonyLowest | ||
Feature: Cache invalidation through HTTP Cache tags (custom TagCollector service) | ||
In order to have a fast API | ||
As an API software developer | ||
I need to store API responses in a cache | ||
|
||
@createSchema | ||
Scenario: Create a dummy resource | ||
When I add "Content-Type" header equal to "application/ld+json" | ||
And I send a "POST" request to "/relation_embedders" with body: | ||
""" | ||
{ | ||
} | ||
""" | ||
Then the response status code should be 201 | ||
And the header "Cache-Tags" should not exist | ||
|
||
Scenario: TagCollector can identify $object (IRI is overriden with custom logic) | ||
When I send a "GET" request to "/relation_embedders/1" | ||
Then the response status code should be 200 | ||
And the header "Cache-Tags" should be equal to "/RE/1#anotherRelated,/RE/1#related,/RE/1" | ||
|
||
Scenario: Create some embedded resources | ||
When I add "Content-Type" header equal to "application/ld+json" | ||
And I send a "POST" request to "/relation_embedders" with body: | ||
""" | ||
{ | ||
"anotherRelated": { | ||
"name": "Related" | ||
} | ||
} | ||
""" | ||
Then the response status code should be 201 | ||
And the header "Cache-Tags" should not exist | ||
|
||
Scenario: TagCollector can add cache tags for relations | ||
When I send a "GET" request to "/relation_embedders/2" | ||
Then the response status code should be 200 | ||
And the header "Cache-Tags" should be equal to "/related_dummies/1#thirdLevel,/related_dummies/1,/RE/2#anotherRelated,/RE/2#related,/RE/2" | ||
|
||
Scenario: Create resource with extraProperties on ApiProperty | ||
When I add "Content-Type" header equal to "application/ld+json" | ||
And I send a "POST" request to "/extra_properties_on_properties" with body: | ||
""" | ||
{ | ||
} | ||
""" | ||
Then the response status code should be 201 | ||
And the header "Cache-Tags" should not exist | ||
|
||
Scenario: TagCollector can read propertyMetadata (tag is overriden with data from extraProperties) | ||
When I send a "GET" request to "/extra_properties_on_properties/1" | ||
Then the response status code should be 200 | ||
And the header "Cache-Tags" should be equal to "/extra_properties_on_properties/1#overrideRelationTag,/extra_properties_on_properties/1" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the API Platform project. | ||
* | ||
* (c) Kévin Dunglas <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ApiPlatform\Serializer; | ||
|
||
/** | ||
* Interface for collecting cache tags during normalization. | ||
* | ||
* @author Urban Suppiger <[email protected]> | ||
*/ | ||
interface TagCollectorInterface | ||
{ | ||
/** | ||
* Collect cache tags for cache invalidation. | ||
* | ||
* @param array<string, mixed>&array{iri?: string, data?: mixed, object?: mixed, property_metadata?: \ApiPlatform\Metadata\ApiProperty, api_attribute?: string, resources?: array<string, string>} $context | ||
*/ | ||
public function collect(array $context = []): void; | ||
usu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.