api-platform / api-platform/core
HTTP cache invalidation: sub-resource collections need an extension point
- Dominant language
- PHP
- Stars
- 2.6k
- Forks
- 980
- Avg merge
- 2d 5h
- Merged PRs (30d)
- 48
Description
## Problem
`PurgeHttpCacheListener` (Symfony Doctrine and Laravel Eloquent) cannot invalidate sub-resource collection operations such as `/parents/{parentId}/children`. Resolving the IRI requires parent `uriVariables` that the listener does not have when it sees the modified entity, so those collection tags are silently skipped.
## Pragmatic solution
Expose a public extension point — symmetric to `Serializer\TagCollectorInterface` on the response side — that the listener consults to collect extra tags for a given entity:
```php
namespace ApiPlatform\HttpCache;
interface PurgeTagProviderInterface
{
/**
* @return iterable additional cache tags to invalidate for $entity
*/
public function getTagsForResource(object $entity): iterable;
}
```
Wiring:
- Tagged service (Symfony) / iterator binding (Laravel), aggregated and injected into `PurgeHttpCacheListener`.
- The listener appends whatever the providers yield to its existing tag set.
- Default ships with no provider — users opt in.
This keeps identifier-finding out of the framework (the user knows how their child invalidates their parents) and lets each project plug exactly the strategy that fits its routing (parent uri_variables, surrogate-key prefixes, class-based tags, etc.).
## Scope
- Add the interface in `src/HttpCache/`.
- Inject `iterable` (optional, default empty) into both Symfony and Laravel `PurgeHttpCacheListener`.
- Document the seam alongside `TagCollectorInterface`.
Contributor guide
Assessment
This issue has not been assessed yet.