Skip to content

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

@soyuka

Description

@soyuka

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:

namespace ApiPlatform\HttpCache;

interface PurgeTagProviderInterface
{
    /**
     * @return iterable<string> 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<PurgeTagProviderInterface> (optional, default empty) into both Symfony and Laravel PurgeHttpCacheListener.
  • Document the seam alongside TagCollectorInterface.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions