Skip to content

fix(httpcache): generating iri cache tag for collection operation with path para… #7152

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

Conversation

JakovKnezovicc
Copy link

@JakovKnezovicc JakovKnezovicc commented May 15, 2025

Q A
Branch? main
Tickets -
License MIT
Doc PR -

Fix: Generating IRI Cache Tag for collection operation with path parameter
This pull request addresses an issue in the PurgeHttpCacheListener where the IRI cache tag for collection operations was not being generated when path parameters were involved.

Changes:

  • Updated the gatherResourceAndItemTags method to use the entity directly when generating the IRI for a collection operation, instead of resolving the resource class. I think it should not be an issue as IriConverter handles non resource objects.
  • Adjusted local operation cache key setting for collection operations

Simplified Use Case:
Consider an entity A with a OneToMany relationship to entity B. The collection operation URI template for entity B might look like /a/{id}/b. Since entity B is only relevant in the context of its parent entity A, when updating A, we want to purge the cache using the tag /a/{id}/b instead of /b. This ensures that we avoid purging cache for all responses containing B tags, maintaining more precise cache invalidation.

@@ -111,14 +111,13 @@ public function postFlush(): void
private function gatherResourceAndItemTags(object $entity, bool $purgeItem): void
{
try {
$resourceClass = $this->resourceClassResolver->getResourceClass($entity);
$iri = $this->iriConverter->getIriFromResource($resourceClass, UrlGeneratorInterface::ABS_PATH, new GetCollection());
$iri = $this->iriConverter->getIriFromResource($entity, UrlGeneratorInterface::ABS_PATH, new GetCollection());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the patch looks fine though we should add some non-regression test

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the patch looks fine though we should add some non-regression test

Can you give me some examples/pointers for non-regression tests? Do you need me to do those tests?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

first thing would be to check the existing tests as I see that many are failing. Inside CONTRIBUTING.md there are lots of informations about running tests and contribution.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

first thing would be to check the existing tests as I see that many are failing. Inside CONTRIBUTING.md there are lots of informations about running tests and contribution.

I will look into it as soon as i can.

@JakovKnezovicc JakovKnezovicc force-pushed the generate_collection_tag_for_cache branch 4 times, most recently from b70f8b6 to db54f89 Compare May 22, 2025 07:53
@JakovKnezovicc JakovKnezovicc changed the title Fix: generating iri cache tag for collection operation with path para… fix(httpcache): generating iri cache tag for collection operation with path para… May 22, 2025
@soyuka soyuka force-pushed the generate_collection_tag_for_cache branch from db54f89 to 32c12a9 Compare May 22, 2025 08:32
@soyuka soyuka changed the base branch from main to 4.1 May 22, 2025 08:32
@soyuka
Copy link
Member

soyuka commented May 22, 2025

Many thanks, I rebased against 4.1 and squashed your commits

@soyuka soyuka force-pushed the generate_collection_tag_for_cache branch from 32c12a9 to 7880953 Compare May 22, 2025 08:33
@soyuka soyuka merged commit 470c2e8 into api-platform:4.1 May 22, 2025
92 of 94 checks passed
@soyuka
Copy link
Member

soyuka commented May 22, 2025

thanks @JakovKnezovicc !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants