Skip to content

Commit

Permalink
DDC-3078 - adding API for cache instantiation to the configuration ob…
Browse files Browse the repository at this point in the history
…ject
  • Loading branch information
Ocramius authored and fabios committed Apr 17, 2014
1 parent 1b5eb55 commit e5f79d1
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions lib/Doctrine/ORM/Cache/CacheConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

namespace Doctrine\ORM\Cache;

use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\ORMException;
use Doctrine\ORM\Cache\Logging\CacheLogger;

Expand Down Expand Up @@ -51,6 +52,11 @@ class CacheConfiguration
*/
private $queryValidator;

/**
* @var callable|null
*/
private $cacheInstantiator;

/**
* @var string
*/
Expand Down Expand Up @@ -130,6 +136,35 @@ public function setQueryValidator(QueryCacheValidator $validator)
$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
*
Expand Down

0 comments on commit e5f79d1

Please sign in to comment.