api-platform / api-platform/core

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

未關閉
#7,965 0 則留言 1 個 reaction 已指派 0 人 在 GitHub 檢視
performance
主要語言
PHP
星號
2.6k
分支
980
平均合併
2 天 5 小時
30 天內合併 PR
48

描述

## 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`.

貢獻指南

開啟貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。