2424use Doctrine \ORM \PersistentCollection ;
2525use Doctrine \ORM \Persisters \Entity \EntityPersister ;
2626use Doctrine \ORM \Proxy \DefaultProxyClassNameResolver ;
27+ use Doctrine \ORM \Query \FilterCollection ;
2728use Doctrine \ORM \Query \ResultSetMapping ;
2829use Doctrine \ORM \UnitOfWork ;
2930
3031use function array_merge ;
32+ use function func_get_args ;
3133use function serialize ;
3234use function sha1 ;
3335
@@ -43,6 +45,7 @@ abstract class AbstractEntityPersister implements CachedEntityPersister
4345 protected TimestampCacheKey $ timestampKey ;
4446 protected EntityHydrator $ hydrator ;
4547 protected Cache $ cache ;
48+ protected FilterCollection $ filters ;
4649 protected CacheLogger |null $ cacheLogger = null ;
4750 protected string $ regionName ;
4851
@@ -64,6 +67,7 @@ public function __construct(
6467 $ cacheFactory = $ cacheConfig ->getCacheFactory ();
6568
6669 $ this ->cache = $ em ->getCache ();
70+ $ this ->filters = $ em ->getFilters ();
6771 $ this ->regionName = $ region ->getName ();
6872 $ this ->uow = $ em ->getUnitOfWork ();
6973 $ this ->metadataFactory = $ em ->getMetadataFactory ();
@@ -215,7 +219,7 @@ protected function getHash(
215219 ? $ this ->persister ->expandCriteriaParameters ($ criteria )
216220 : $ this ->persister ->expandParameters ($ criteria );
217221
218- return sha1 ($ query . serialize ($ params ) . serialize ($ orderBy ) . $ limit . $ offset );
222+ return sha1 ($ query . serialize ($ params ) . serialize ($ orderBy ) . $ limit . $ offset . $ this -> filters -> getHash () );
219223 }
220224
221225 /**
@@ -472,7 +476,7 @@ public function loadManyToManyCollection(
472476 }
473477
474478 $ ownerId = $ this ->uow ->getEntityIdentifier ($ collection ->getOwner ());
475- $ key = $ this ->buildCollectionCacheKey ($ assoc , $ ownerId );
479+ $ key = $ this ->buildCollectionCacheKey ($ assoc , $ ownerId, $ this -> filters -> getHash () );
476480 $ list = $ persister ->loadCollectionCache ($ collection , $ key );
477481
478482 if ($ list !== null ) {
@@ -503,7 +507,7 @@ public function loadOneToManyCollection(
503507 }
504508
505509 $ ownerId = $ this ->uow ->getEntityIdentifier ($ collection ->getOwner ());
506- $ key = $ this ->buildCollectionCacheKey ($ assoc , $ ownerId );
510+ $ key = $ this ->buildCollectionCacheKey ($ assoc , $ ownerId, $ this -> filters -> getHash () );
507511 $ list = $ persister ->loadCollectionCache ($ collection , $ key );
508512
509513 if ($ list !== null ) {
@@ -546,12 +550,15 @@ public function refresh(array $id, object $entity, LockMode|int|null $lockMode =
546550 }
547551
548552 /** @param array<string, mixed> $ownerId */
549- protected function buildCollectionCacheKey (AssociationMapping $ association , array $ ownerId ): CollectionCacheKey
553+ protected function buildCollectionCacheKey (AssociationMapping $ association , array $ ownerId, /* string $filterHash */ ): CollectionCacheKey
550554 {
555+ $ filterHash = (string ) (func_get_args ()[2 ] ?? '' ); // todo: move to argument in next major release
556+
551557 return new CollectionCacheKey (
552558 $ this ->metadataFactory ->getMetadataFor ($ association ->sourceEntity )->rootEntityName ,
553559 $ association ->fieldName ,
554560 $ ownerId ,
561+ $ filterHash ,
555562 );
556563 }
557564}
0 commit comments