1
0
mirror of synced 2025-01-31 12:32:59 +03:00

DDC-3078 - adding API for cache instantiation to the configuration object

This commit is contained in:
Marco Pivetta 2014-04-10 03:01:28 +02:00 committed by fabios
parent 1b5eb55ed9
commit e5f79d1f73

View File

@ -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
*