diff --git a/lib/Doctrine/ORM/Cache/DefaultQueryCache.php b/lib/Doctrine/ORM/Cache/DefaultQueryCache.php index 07c9d8f4348..eb28e420b92 100644 --- a/lib/Doctrine/ORM/Cache/DefaultQueryCache.php +++ b/lib/Doctrine/ORM/Cache/DefaultQueryCache.php @@ -112,20 +112,29 @@ public function get(QueryCacheKey $key, ResultSetMapping $rsm, array $hints = ar $regionName = $region->getName(); $cm = $this->em->getClassMetadata($entityName); + + $entityCacheKeys = []; + foreach ($entry->result as $index => $concreteEntry) { + $entityCacheKeys[$index] = new EntityCacheKey($cm->rootEntityName, $concreteEntry['identifier']); + } + $entries = $region->getMultiple(new CollectionCacheEntry($entityCacheKeys)); + // @TODO - move to cache hydration component foreach ($entry->result as $index => $entry) { - if (($entityEntry = $region->get($entityKey = new EntityCacheKey($cm->rootEntityName, $entry['identifier']))) === null) { + $entityEntry = is_array($entries) && array_key_exists($index, $entries) ? $entries[$index] : null; + + if ($entityEntry === null) { if ($this->cacheLogger !== null) { - $this->cacheLogger->entityCacheMiss($regionName, $entityKey); + $this->cacheLogger->entityCacheMiss($regionName, $entityCacheKeys[$index]); } return null; } if ($this->cacheLogger !== null) { - $this->cacheLogger->entityCacheHit($regionName, $entityKey); + $this->cacheLogger->entityCacheHit($regionName, $entityCacheKeys[$index]); } if ( ! $hasRelation) { diff --git a/tests/Doctrine/Tests/ORM/Cache/DefaultQueryCacheTest.php b/tests/Doctrine/Tests/ORM/Cache/DefaultQueryCacheTest.php index 2de9c66984d..44c13f22a25 100644 --- a/tests/Doctrine/Tests/ORM/Cache/DefaultQueryCacheTest.php +++ b/tests/Doctrine/Tests/ORM/Cache/DefaultQueryCacheTest.php @@ -276,8 +276,10 @@ public function testGetBasicQueryResult() ); $this->region->addReturn('get', $entry); - $this->region->addReturn('get', new EntityCacheEntry(Country::CLASSNAME, $data[0])); - $this->region->addReturn('get', new EntityCacheEntry(Country::CLASSNAME, $data[1])); + $this->region->addReturn('getMultiple', array( + new EntityCacheEntry(Country::CLASSNAME, $data[0]), + new EntityCacheEntry(Country::CLASSNAME, $data[1]) + )); $rsm->addRootEntityFromClassMetadata(Country::CLASSNAME, 'c'); @@ -434,8 +436,10 @@ public function testGetShouldIgnoreOldQueryCacheEntryResult() $entry->time = time() - 100; $this->region->addReturn('get', $entry); - $this->region->addReturn('get', new EntityCacheEntry(Country::CLASSNAME, $entities[0])); - $this->region->addReturn('get', new EntityCacheEntry(Country::CLASSNAME, $entities[1])); + $this->region->addReturn('getMultiple', array( + new EntityCacheEntry(Country::CLASSNAME, $entities[0]), + new EntityCacheEntry(Country::CLASSNAME, $entities[1]) + )); $rsm->addRootEntityFromClassMetadata(Country::CLASSNAME, 'c'); @@ -457,8 +461,10 @@ public function testGetShouldIgnoreNonQueryCacheEntryResult() ); $this->region->addReturn('get', $entry); - $this->region->addReturn('get', new EntityCacheEntry(Country::CLASSNAME, $data[0])); - $this->region->addReturn('get', new EntityCacheEntry(Country::CLASSNAME, $data[1])); + $this->region->addReturn('getMultiple', array( + new EntityCacheEntry(Country::CLASSNAME, $data[0]), + new EntityCacheEntry(Country::CLASSNAME, $data[1]) + )); $rsm->addRootEntityFromClassMetadata(Country::CLASSNAME, 'c'); @@ -475,7 +481,7 @@ public function testGetShouldIgnoreMissingEntityQueryCacheEntry() )); $this->region->addReturn('get', $entry); - $this->region->addReturn('get', null); + $this->region->addReturn('getMultiple', [null]); $rsm->addRootEntityFromClassMetadata(Country::CLASSNAME, 'c');