-
-
Notifications
You must be signed in to change notification settings - Fork 900
Purge parent collections in inheritance cases #7034
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Labels
Comments
For now I created the following processor decorator to work-around the issue: #[AsDecorator(decorates: 'api_platform.doctrine.orm.state.persist_processor')]
final readonly class PurgeParentCacheCollection implements ProcessorInterface
{
public function __construct(
#[Autowire(service: 'api_platform.http_cache.purger')]
private PurgerInterface $purger,
private PersistProcessor $persistProcessor,
private IriConverterInterface $iriConverter,
private ResourceClassResolverInterface $resourceClassResolver,
private EntityManagerInterface $entityManager,
) {}
public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): mixed
{
$toReturn = $this->persistProcessor->process($data, $operation, $uriVariables, $context);
$classMetadata = $this->entityManager->getClassMetadata($data::class);
if ($classMetadata->isInheritanceTypeNone()) {
return $toReturn;
}
foreach ($classMetadata->parentClasses as $parentClass) {
if ($this->resourceClassResolver->isResourceClass($parentClass)) {
$iris[] = $this->iriConverter->getIriFromResource($parentClass, UrlGeneratorInterface::ABS_PATH, new GetCollection());
}
}
if (!empty($iris)) {
$this->purger->purge($iris);
}
return $toReturn;
}
} |
Interesting, we should probably handle this directly inside the PurgeListener, would you be able to patch this? Thanks! |
Ok I'll try. I think you need tests for this too? @soyuka |
This was referenced Mar 22, 2025
Closed
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Description
In the case when we clear the cache, we haven't covered the scenario where an entity is part of a class hierarchy (such as STI). In this case, the cache for all parent collections should also be cleared.
For example, we have a Product and its subclass ChildProduct. If we already have a Products collection in the cache, when a new ChildProduct is created, only the cache for the ChildProduct collection will be purged, while the parent collection will remain unchanged.
In my opinion, this is more of a bug than a feature request.
The text was updated successfully, but these errors were encountered: