Skip to content

feat(httpcache): introduce PurgeTagProviderInterface extension point#7970

Open
guillaumedelre wants to merge 1 commit into
api-platform:mainfrom
guillaumedelre:feature/http-cache-purge-tag-provider
Open

feat(httpcache): introduce PurgeTagProviderInterface extension point#7970
guillaumedelre wants to merge 1 commit into
api-platform:mainfrom
guillaumedelre:feature/http-cache-purge-tag-provider

Conversation

@guillaumedelre
Copy link
Copy Markdown
Contributor

@guillaumedelre guillaumedelre commented May 11, 2026

Summary

  • Introduces `ApiPlatform\HttpCache\PurgeTagProviderInterface` to let users invalidate additional cache tags (e.g. sub-resource collection IRIs like `/parents/{id}/children`) that `PurgeHttpCacheListener` cannot resolve on its own because it lacks the parent `uriVariables`
  • Symfony: services tagged `api_platform.http_cache.purge_tag_provider` are automatically injected via `tagged_iterator`
  • Laravel: implementations tagged with `PurgeTagProviderInterface::class` via `$app->tag()` are injected automatically

Closes #7965

Documentation

api-platform/docs#2282

Test plan

  • `vendor/bin/phpunit src/Symfony/Tests/Doctrine/EventListener/PurgeHttpCacheListenerTest.php` — 7 tests pass including `testPurgeTagProviders`
  • `vendor/bin/phpstan analyse src/HttpCache/PurgeTagProviderInterface.php src/Symfony/Doctrine/EventListener/PurgeHttpCacheListener.php src/Laravel/Eloquent/Listener/PurgeHttpCacheListener.php src/Laravel/Eloquent/ApiPlatformEventProvider.php` — no errors
  • `vendor/bin/php-cs-fixer fix --diff` — no changes

@guillaumedelre
Copy link
Copy Markdown
Contributor Author

guillaumedelre commented May 11, 2026

The associated documentation PR is available at api-platform/docs#2282.

cc @soyuka @dunglas @alanpoulain

PurgeHttpCacheListener cannot invalidate sub-resource collection IRIs
such as /parents/{id}/children because it lacks the parent uri_variables
when processing the child entity. The new PurgeTagProviderInterface
lets users plug in custom tag collection strategies for these cases.

Symfony: implementing PurgeTagProviderInterface is sufficient; the
registerForAutoconfiguration hook tags the service automatically with
api_platform.http_cache.purge_tag_provider. Laravel: bind implementations
and tag them with PurgeTagProviderInterface::class via $app->tag().

Signed-off-by: Guillaume Delré <delre.guillaume@gmail.com>
@guillaumedelre guillaumedelre force-pushed the feature/http-cache-purge-tag-provider branch from 851f135 to daa7ad5 Compare May 12, 2026 05:33
@soyuka
Copy link
Copy Markdown
Member

soyuka commented May 12, 2026

Ah yeah I opened #7965 because of #7951

Can you not ping maintainers please its annoying.

@guillaumedelre
Copy link
Copy Markdown
Contributor Author

Sorry for the ping, I've made it because it's in the CONTRIBUTING.md

Also don't forget to add a comment when you update a PR with a ping to [the maintainers](https://github.com/orgs/api-platform/people), so he/she will get a notification.

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.

HTTP cache invalidation: sub-resource collections need an extension point

2 participants