HTTP cache invalidation: sub-resource collections need an extension point · Issue #7965 · api-platform/core · GitHub
Skip to content

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

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions