DDC-3078 - adding API for cache instantiation to the configuration object
This commit is contained in:
parent
1b5eb55ed9
commit
e5f79d1f73
@ -20,6 +20,7 @@
|
||||
|
||||
namespace Doctrine\ORM\Cache;
|
||||
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\ORMException;
|
||||
use Doctrine\ORM\Cache\Logging\CacheLogger;
|
||||
|
||||
@ -51,6 +52,11 @@ class CacheConfiguration
|
||||
*/
|
||||
private $queryValidator;
|
||||
|
||||
/**
|
||||
* @var callable|null
|
||||
*/
|
||||
private $cacheInstantiator;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
@ -130,6 +136,35 @@ class CacheConfiguration
|
||||
$this->queryValidator = $validator;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
public function setCacheInstantiator($instantiator)
|
||||
{
|
||||
if ( ! is_callable($instantiator)) {
|
||||
throw ORMException::invalidSecondLevelCacheInstantiator($instantiator);
|
||||
}
|
||||
|
||||
$this->cacheInstantiator = $instantiator;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return callable that
|
||||
*/
|
||||
public function getCacheInstantiator()
|
||||
{
|
||||
if ( ! $this->cacheInstantiator) {
|
||||
$this->cacheInstantiator = function (EntityManagerInterface $entityManager) {
|
||||
return new DefaultCache($entityManager);
|
||||
};
|
||||
}
|
||||
|
||||
return $this->cacheInstantiator;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $className
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user