DDC-3078 - cache instantiator is used in the ORM instead of callables
This commit is contained in:
parent
4b388b2ce8
commit
df6a411365
3 changed files with 9 additions and 38 deletions
|
@ -53,7 +53,7 @@ class CacheConfiguration
|
|||
private $queryValidator;
|
||||
|
||||
/**
|
||||
* @var callable|null
|
||||
* @var CacheInstantiator|null
|
||||
*/
|
||||
private $cacheInstantiator;
|
||||
|
||||
|
@ -132,31 +132,18 @@ class CacheConfiguration
|
|||
}
|
||||
|
||||
/**
|
||||
* @param callable $instantiator responsible of retrieving an {@see \Doctrine\ORM\Cache} instance given
|
||||
* a {@see \Doctrine\ORM\EntityManagerInterface} instance
|
||||
*
|
||||
* @throws ORMException if the given instantiator is not a valid callable
|
||||
* @param CacheInstantiator
|
||||
*/
|
||||
public function setCacheInstantiator($instantiator)
|
||||
public function setCacheInstantiator(CacheInstantiator $cacheInstantiator)
|
||||
{
|
||||
if ( ! is_callable($instantiator)) {
|
||||
throw ORMException::invalidSecondLevelCacheInstantiator($instantiator);
|
||||
}
|
||||
|
||||
$this->cacheInstantiator = $instantiator;
|
||||
$this->cacheInstantiator = $cacheInstantiator;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return callable that
|
||||
* @return CacheInstantiator
|
||||
*/
|
||||
public function getCacheInstantiator()
|
||||
{
|
||||
if ( ! $this->cacheInstantiator) {
|
||||
$this->cacheInstantiator = function (EntityManagerInterface $entityManager) {
|
||||
return new DefaultCache($entityManager);
|
||||
};
|
||||
}
|
||||
|
||||
return $this->cacheInstantiator;
|
||||
return $this->cacheInstantiator ?: $this->cacheInstantiator = new DefaultCacheInstantiator();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -166,8 +166,7 @@ use Doctrine\Common\Util\ClassUtils;
|
|||
);
|
||||
|
||||
if ($config->isSecondLevelCacheEnabled()) {
|
||||
$cacheInstantiator = $config->getSecondLevelCacheConfiguration()->getCacheInstantiator();
|
||||
$this->cache = $cacheInstantiator($this);
|
||||
$this->cache = $config->getSecondLevelCacheConfiguration()->getCacheInstantiator()->getCache($this);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -32,18 +32,7 @@ class CacheConfigTest extends DoctrineTestCase
|
|||
*/
|
||||
public function testGetDefaultCacheIstantiator()
|
||||
{
|
||||
$entityManager = $this->getMock('Doctrine\ORM\EntityManagerInterface');
|
||||
$config = $this->getMock('Doctrine\ORM\Configuration');
|
||||
|
||||
$entityManager->expects($this->any())->method('getConfiguration')->will($this->returnValue($config));
|
||||
$config
|
||||
->expects($this->any())
|
||||
->method('getSecondLevelCacheConfiguration')
|
||||
->will($this->returnValue($this->config));
|
||||
|
||||
$defaultIstantiator = $this->config->getCacheInstantiator();
|
||||
|
||||
$this->assertInstanceOf('Doctrine\ORM\Cache\DefaultCache', $defaultIstantiator($entityManager));
|
||||
$this->assertInstanceOf('Doctrine\ORM\Cache\DefaultInstantiator', $this->config->getCacheInstantiator());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -51,14 +40,10 @@ class CacheConfigTest extends DoctrineTestCase
|
|||
*/
|
||||
public function testSetGetCacheIstantiator()
|
||||
{
|
||||
$istantiator = function () {};
|
||||
$istantiator = $this->getMock('Doctrine\ORM\Cache\CacheInstantiator');
|
||||
|
||||
$this->config->setCacheInstantiator($istantiator);
|
||||
$this->assertSame($istantiator, $this->config->getCacheInstantiator());
|
||||
|
||||
$this->setExpectedException('Doctrine\ORM\ORMException');
|
||||
|
||||
$this->config->setCacheInstantiator(null);
|
||||
}
|
||||
|
||||
public function testSetGetRegionLifetime()
|
||||
|
|
Loading…
Add table
Reference in a new issue