DDC-3078 - Use CacheFactory instead of cache instantiator
This commit is contained in:
parent
fa1cc9269c
commit
1dc3396ad4
@ -50,11 +50,6 @@ class CacheConfiguration
|
||||
*/
|
||||
private $queryValidator;
|
||||
|
||||
/**
|
||||
* @var CacheInstantiator|null
|
||||
*/
|
||||
private $cacheInstantiator;
|
||||
|
||||
/**
|
||||
* @return \Doctrine\ORM\Cache\CacheFactory|null
|
||||
*/
|
||||
@ -128,20 +123,4 @@ class CacheConfiguration
|
||||
{
|
||||
$this->queryValidator = $validator;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CacheInstantiator
|
||||
*/
|
||||
public function setCacheInstantiator(CacheInstantiator $cacheInstantiator)
|
||||
{
|
||||
$this->cacheInstantiator = $cacheInstantiator;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return CacheInstantiator
|
||||
*/
|
||||
public function getCacheInstantiator()
|
||||
{
|
||||
return $this->cacheInstantiator ?: $this->cacheInstantiator = new DefaultCacheInstantiator();
|
||||
}
|
||||
}
|
||||
|
@ -101,4 +101,13 @@ interface CacheFactory
|
||||
* @return \Doctrine\ORM\Cache\TimestampRegion The timestamp region.
|
||||
*/
|
||||
public function getTimestampRegion();
|
||||
|
||||
/**
|
||||
* Build \Doctrine\ORM\Cache
|
||||
*
|
||||
* @param EntityManagerInterface $entityManager
|
||||
*
|
||||
* @return \Doctrine\ORM\Cache
|
||||
*/
|
||||
public function createCache(EntityManagerInterface $entityManager);
|
||||
}
|
||||
|
@ -1,41 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\ORM\Cache;
|
||||
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
/**
|
||||
* Contract for building second level cache instances.
|
||||
*
|
||||
* @since 2.5
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
*/
|
||||
interface CacheInstantiator
|
||||
{
|
||||
/**
|
||||
* Build timestamp cache region
|
||||
*
|
||||
* @param EntityManagerInterface $entityManager
|
||||
*
|
||||
* @return \Doctrine\ORM\Cache
|
||||
*/
|
||||
public function getCache(EntityManagerInterface $entityManager);
|
||||
}
|
@ -230,4 +230,12 @@ class DefaultCacheFactory implements CacheFactory
|
||||
|
||||
return $this->timestampRegion;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function createCache(EntityManagerInterface $em)
|
||||
{
|
||||
return new DefaultCache($em);
|
||||
}
|
||||
}
|
||||
|
@ -1,41 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\ORM\Cache;
|
||||
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
/**
|
||||
* Default implementation of the {@see \Doctrine\ORM\Cache\CacheInstantiator}, responsible
|
||||
* for producing an {@see \Doctrine\ORM\Cache\DefaultCache}
|
||||
*
|
||||
* @since 2.5
|
||||
* @author Marco Pivetta <ocramius@gmail.com>
|
||||
*/
|
||||
class DefaultCacheInstantiator implements CacheInstantiator
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getCache(EntityManagerInterface $entityManager)
|
||||
{
|
||||
return new DefaultCache($entityManager);
|
||||
}
|
||||
}
|
@ -166,7 +166,9 @@ use Doctrine\Common\Util\ClassUtils;
|
||||
);
|
||||
|
||||
if ($config->isSecondLevelCacheEnabled()) {
|
||||
$this->cache = $config->getSecondLevelCacheConfiguration()->getCacheInstantiator()->getCache($this);
|
||||
$cacheConfig = $config->getSecondLevelCacheConfiguration();
|
||||
$cacheFactory = $cacheConfig->getCacheFactory();
|
||||
$this->cache = $cacheFactory->createCache($this);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -27,25 +27,6 @@ class CacheConfigTest extends DoctrineTestCase
|
||||
$this->config = new CacheConfiguration();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Doctrine\ORM\Cache\CacheConfiguration::getCacheInstantiator
|
||||
*/
|
||||
public function testGetDefaultCacheIstantiator()
|
||||
{
|
||||
$this->assertInstanceOf('Doctrine\ORM\Cache\DefaultCacheInstantiator', $this->config->getCacheInstantiator());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Doctrine\ORM\Cache\CacheConfiguration::getCacheInstantiator
|
||||
*/
|
||||
public function testSetGetCacheIstantiator()
|
||||
{
|
||||
$istantiator = $this->getMock('Doctrine\ORM\Cache\CacheInstantiator');
|
||||
|
||||
$this->config->setCacheInstantiator($istantiator);
|
||||
$this->assertSame($istantiator, $this->config->getCacheInstantiator());
|
||||
}
|
||||
|
||||
public function testSetGetRegionLifetime()
|
||||
{
|
||||
$config = $this->config->getRegionsConfiguration();
|
||||
|
@ -1,29 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\ORM\Cache;
|
||||
|
||||
use Doctrine\ORM\Cache\DefaultCacheInstantiator;
|
||||
use Doctrine\Tests\OrmTestCase;
|
||||
|
||||
/**
|
||||
* @covers \Doctrine\ORM\Cache\DefaultCacheInstantiator
|
||||
*/
|
||||
class DefaultCacheInstantiatorTest extends OrmTestCase
|
||||
{
|
||||
public function testGetCache()
|
||||
{
|
||||
$entityManager = $this->getMock('Doctrine\ORM\EntityManagerInterface');
|
||||
$config = $this->getMock('Doctrine\ORM\Configuration');
|
||||
$cacheConfig = $this->getMock('Doctrine\ORM\Cache\CacheConfiguration');
|
||||
|
||||
$entityManager->expects($this->any())->method('getConfiguration')->will($this->returnValue($config));
|
||||
$config
|
||||
->expects($this->any())
|
||||
->method('getSecondLevelCacheConfiguration')
|
||||
->will($this->returnValue($cacheConfig));
|
||||
|
||||
$instantiator = new DefaultCacheInstantiator();
|
||||
|
||||
$this->assertInstanceOf('Doctrine\ORM\Cache\DefaultCache', $instantiator->getCache($entityManager));
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user