Skip to content

Commit

Permalink
Test suite: Second level cache listener should not mark "cacheable" v…
Browse files Browse the repository at this point in the history
…ersioned associations
  • Loading branch information
goetas committed Jan 17, 2015
1 parent c131e32 commit 0b57935
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
12 changes: 6 additions & 6 deletions lib/Doctrine/ORM/Cache/DefaultCacheFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,13 @@ public function buildCollectionHydrator(EntityManagerInterface $em, array $mappi
if ($mapping['cache']) {
$targetPersister = $em->getUnitOfWork()->getEntityPersister($mapping['targetEntity']);

if ($targetPersister instanceof CachedPersister) {

$targetRegion = $targetPersister->getCacheRegion();
if (! ($targetPersister instanceof CachedPersister)) {
throw CacheException::nonCacheableEntity($mapping['targetEntity']);
}
$targetRegion = $targetPersister->getCacheRegion();

if ($targetRegion instanceof MultiGetRegion) {
return new MultiGetCollectionHydrator($em, $targetRegion);
}
if ($targetRegion instanceof MultiGetRegion) {
return new MultiGetCollectionHydrator($em, $targetRegion);
}
}

Expand Down
18 changes: 16 additions & 2 deletions tests/Doctrine/Tests/EventListener/CacheMetadataListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,20 @@

class CacheMetadataListener
{
private $loaded = array();
/**
* @param \Doctrine\Common\Persistence\Event\LoadClassMetadataEventArgs $event
*/
public function loadClassMetadata(LoadClassMetadataEventArgs $event)
{
$metadata = $event->getClassMetadata();

if (isset($this->loaded[$metadata->name])) {
return;
}

$this->loaded[$metadata->name] = true;

$cache = array(
'usage' => ClassMetadata::CACHE_USAGE_NONSTRICT_READ_WRITE
);
Expand All @@ -26,10 +34,16 @@ public function loadClassMetadata(LoadClassMetadataEventArgs $event)
return;
}

$metadata->enableCache($cache);
$factory = $event->getObjectManager()->getMetadataFactory();

$metadata->enableCache($cache);
foreach ($metadata->associationMappings as $mapping) {
$metadata->enableAssociationCache($mapping['fieldName'], $cache);

$targetMetadata = $factory->getMetadataFor($mapping['targetEntity']);

if (!$targetMetadata->isVersioned) {
$metadata->enableAssociationCache($mapping['fieldName'], $cache);
}
}
}
}

0 comments on commit 0b57935

Please sign in to comment.