diff --git a/docs/en/reference/second-level-cache.rst b/docs/en/reference/second-level-cache.rst index 0159eb3246b..63ed0de42ce 100644 --- a/docs/en/reference/second-level-cache.rst +++ b/docs/en/reference/second-level-cache.rst @@ -208,17 +208,20 @@ Built-in Strategies Caching Strategies are responsible for access cache regions. -* ``Doctrine\ORM\Cache\Access\ReadOnlyRegionAccess`` implements ``READ_ONLY`` -* ``Doctrine\ORM\Cache\Access\NonStrictReadWriteRegionAccessStrategy`` implements ``NONSTRICT_READ_WRITE`` -* ``Doctrine\ORM\Cache\Access\ConcurrentRegionAccessStrategy`` implements ``READ_WRITE`` requires a ``ConcurrentRegion`` - -``Doctrine\ORM\Cache\RegionAccess`` and ``Doctrine\ORM\Cache\ConcurrentRegionAccess`` +* ``Doctrine\ORM\Cache\Access\ReadOnlyEntityRegionAccessStrategy`` implements ``READ_ONLY`` for entities +* ``Doctrine\ORM\Cache\Access\ReadOnlyCollectionRegionAccessStrategy`` implements ``READ_ONLY`` for collections +* ``Doctrine\ORM\Cache\Access\NonStrictReadWriteEntityRegionAccessStrategy`` implements ``NONSTRICT_READ_WRITE`` for entities +* ``Doctrine\ORM\Cache\Access\NonStrictReadWriteCollectionRegionAccessStrategy`` implements ``NONSTRICT_READ_WRITE`` for collections +* ``Doctrine\ORM\Cache\Access\ReadWriteEntityRegionAccessStrategy`` implements ``READ_WRITE`` requires a ``ConcurrentRegion`` for entities +* ``Doctrine\ORM\Cache\Access\ReadWriteCollectionRegionAccessStrategy`` implements ``READ_WRITE`` requires a ``ConcurrentRegion`` for collections + +``Doctrine\ORM\Cache\RegionAccessStrategy``, ``Doctrine\ORM\Cache\CollectionRegionAccessStrategy`` and ``Doctrine\ORM\Cache\ConcurrentRegionAccessStrategy`` Defines contracts that should be implemented by caching strategies. -If you want to support locking for ``READ_WRITE`` strategies you should implement ``ConcurrentRegionAccess``; ``RegionAccess`` otherwise. +If you want to support locking for ``READ_WRITE`` strategies you should implement ``ConcurrentRegionAccessStrategy``; ``RegionAccessStrategy`` otherwise. -``Doctrine\ORM\Cache\RegionAccess`` +``Doctrine\ORM\Cache\RegionAccessStrategy`` Interface for all region access strategies. @@ -226,7 +229,7 @@ Interface for all region access strategies. */ -class NonStrictReadWriteRegionAccessStrategy implements RegionAccess +abstract class AbstractRegionAccessStrategy implements RegionAccessStrategy { /** * @var \Doctrine\ORM\Cache\Region */ - private $region; + protected $region; /** * @param \Doctrine\ORM\Cache\Region $region @@ -55,22 +54,6 @@ public function getRegion() return $this->region; } - /** - * {@inheritdoc} - */ - public function afterInsert(CacheKey $key, CacheEntry $entry) - { - return $this->region->put($key, $entry); - } - - /** - * {@inheritdoc} - */ - public function afterUpdate(CacheKey $key, CacheEntry $entry, Lock $lock = null) - { - return $this->region->put($key, $entry); - } - /** * {@inheritdoc} */ diff --git a/lib/Doctrine/ORM/Cache/Access/NonStrictReadWriteCollectionRegionAccessStrategy.php b/lib/Doctrine/ORM/Cache/Access/NonStrictReadWriteCollectionRegionAccessStrategy.php new file mode 100644 index 00000000000..b4257c2244c --- /dev/null +++ b/lib/Doctrine/ORM/Cache/Access/NonStrictReadWriteCollectionRegionAccessStrategy.php @@ -0,0 +1,34 @@ +. + */ + +namespace Doctrine\ORM\Cache\Access; + +use Doctrine\ORM\Cache\CollectionRegionAccessStrategy; + +/** + * Specific non-strict read/write region access strategy + * + * @since 2.5 + * @author Fabio B. Silva + */ +class NonStrictReadWriteCollectionRegionAccessStrategy extends AbstractRegionAccessStrategy implements CollectionRegionAccessStrategy +{ + +} diff --git a/lib/Doctrine/ORM/Cache/Access/NonStrictReadWriteEntityRegionAccessStrategy.php b/lib/Doctrine/ORM/Cache/Access/NonStrictReadWriteEntityRegionAccessStrategy.php new file mode 100644 index 00000000000..24203755247 --- /dev/null +++ b/lib/Doctrine/ORM/Cache/Access/NonStrictReadWriteEntityRegionAccessStrategy.php @@ -0,0 +1,51 @@ +. + */ + +namespace Doctrine\ORM\Cache\Access; + +use Doctrine\ORM\Cache\EntityRegionAccessStrategy; +use Doctrine\ORM\Cache\CacheEntry; +use Doctrine\ORM\Cache\CacheKey; +use Doctrine\ORM\Cache\Lock; + +/** + * Specific non-strict read/write region access strategy + * + * @since 2.5 + * @author Fabio B. Silva + */ +class NonStrictReadWriteEntityRegionAccessStrategy extends AbstractRegionAccessStrategy implements EntityRegionAccessStrategy +{ + /** + * {@inheritdoc} + */ + public function afterInsert(CacheKey $key, CacheEntry $entry) + { + return $this->region->put($key, $entry); + } + + /** + * {@inheritdoc} + */ + public function afterUpdate(CacheKey $key, CacheEntry $entry, Lock $lock = null) + { + return $this->region->put($key, $entry); + } +} diff --git a/lib/Doctrine/ORM/Cache/Access/ReadOnlyCollectionRegionAccessStrategy.php b/lib/Doctrine/ORM/Cache/Access/ReadOnlyCollectionRegionAccessStrategy.php new file mode 100644 index 00000000000..c384ee0ad6b --- /dev/null +++ b/lib/Doctrine/ORM/Cache/Access/ReadOnlyCollectionRegionAccessStrategy.php @@ -0,0 +1,34 @@ +. + */ + +namespace Doctrine\ORM\Cache\Access; + +use Doctrine\ORM\Cache\CollectionRegionAccessStrategy; + +/** + * Specific read-only region access strategy + * + * @since 2.5 + * @author Fabio B. Silva + */ +class ReadOnlyCollectionRegionAccessStrategy extends AbstractRegionAccessStrategy implements CollectionRegionAccessStrategy +{ + +} diff --git a/lib/Doctrine/ORM/Cache/Access/ReadOnlyRegionAccess.php b/lib/Doctrine/ORM/Cache/Access/ReadOnlyEntityRegionAccessStrategy.php similarity index 94% rename from lib/Doctrine/ORM/Cache/Access/ReadOnlyRegionAccess.php rename to lib/Doctrine/ORM/Cache/Access/ReadOnlyEntityRegionAccessStrategy.php index 14698a96a67..4f4372393b5 100644 --- a/lib/Doctrine/ORM/Cache/Access/ReadOnlyRegionAccess.php +++ b/lib/Doctrine/ORM/Cache/Access/ReadOnlyEntityRegionAccessStrategy.php @@ -31,7 +31,7 @@ * @since 2.5 * @author Fabio B. Silva */ -class ReadOnlyRegionAccess extends NonStrictReadWriteRegionAccessStrategy +class ReadOnlyEntityRegionAccessStrategy extends NonStrictReadWriteEntityRegionAccessStrategy { /** * {@inheritdoc} diff --git a/lib/Doctrine/ORM/Cache/Access/ReadWriteCollectionRegionAccessStrategy.php b/lib/Doctrine/ORM/Cache/Access/ReadWriteCollectionRegionAccessStrategy.php new file mode 100644 index 00000000000..e2da56d26ef --- /dev/null +++ b/lib/Doctrine/ORM/Cache/Access/ReadWriteCollectionRegionAccessStrategy.php @@ -0,0 +1,102 @@ +. + */ + +namespace Doctrine\ORM\Cache\Access; + +use Doctrine\ORM\Cache\ConcurrentRegionAccessStrategy; +use Doctrine\ORM\Cache\CollectionRegionAccessStrategy; +use Doctrine\ORM\Cache\ConcurrentRegion; +use Doctrine\ORM\Cache\CacheException; +use Doctrine\ORM\Cache\LockException; +use Doctrine\ORM\Cache\CacheEntry; +use Doctrine\ORM\Cache\CacheKey; +use Doctrine\ORM\Cache\Lock; + +/** + * Region access strategies for concurrently managed data. + * + * @since 2.5 + * @author Fabio B. Silva + */ +class ReadWriteCollectionRegionAccessStrategy extends AbstractRegionAccessStrategy implements ConcurrentRegionAccessStrategy, CollectionRegionAccessStrategy +{ + /** + * @param \Doctrine\ORM\Cache\ConcurrentRegion $region + */ + public function __construct(ConcurrentRegion $region) + { + $this->region = $region; + } + + /** + * {@inheritdoc} + */ + public function put(CacheKey $key, CacheEntry $entry) + { + $writeLock = null; + + try { + if ( ! ($writeLock = $this->region->writeLock($key))) { + return false; + } + + if ( ! $this->region->put($key, $entry, $writeLock)) { + return false; + } + + $this->region->writeUnlock($key, $writeLock); + + return true; + + } catch (LockException $exc) { + + if ($writeLock) { + $this->region->writeUnlock($key, $writeLock); + } + + throw new $exc; + } catch (\Exception $exc) { + + if ($writeLock) { + $this->region->writeUnlock($key, $writeLock); + } + + throw new CacheException($exc->getMessage(), $exc->getCode(), $exc); + } + + return false; + } + + /** + * {@inheritdoc} + */ + public function lockItem(CacheKey $key) + { + return $this->region->readLock($key); + } + + /** + * {@inheritdoc} + */ + public function unlockItem(CacheKey $key, Lock $lock) + { + return $this->region->readUnlock($key, $lock); + } +} diff --git a/lib/Doctrine/ORM/Cache/Access/ConcurrentRegionAccessStrategy.php b/lib/Doctrine/ORM/Cache/Access/ReadWriteEntityRegionAccessStrategy.php similarity index 81% rename from lib/Doctrine/ORM/Cache/Access/ConcurrentRegionAccessStrategy.php rename to lib/Doctrine/ORM/Cache/Access/ReadWriteEntityRegionAccessStrategy.php index c2b90bab0ec..77b5818924a 100644 --- a/lib/Doctrine/ORM/Cache/Access/ConcurrentRegionAccessStrategy.php +++ b/lib/Doctrine/ORM/Cache/Access/ReadWriteEntityRegionAccessStrategy.php @@ -20,7 +20,8 @@ namespace Doctrine\ORM\Cache\Access; -use Doctrine\ORM\Cache\ConcurrentRegionAccess; +use Doctrine\ORM\Cache\ConcurrentRegionAccessStrategy; +use Doctrine\ORM\Cache\EntityRegionAccessStrategy; use Doctrine\ORM\Cache\ConcurrentRegion; use Doctrine\ORM\Cache\CacheException; use Doctrine\ORM\Cache\LockException; @@ -34,13 +35,8 @@ * @since 2.5 * @author Fabio B. Silva */ -class ConcurrentRegionAccessStrategy implements ConcurrentRegionAccess +class ReadWriteEntityRegionAccessStrategy extends AbstractRegionAccessStrategy implements ConcurrentRegionAccessStrategy, EntityRegionAccessStrategy { - /** - * @var \Doctrine\ORM\Cache\ConcurrentRegion - */ - private $region; - /** * @param \Doctrine\ORM\Cache\ConcurrentRegion $region */ @@ -49,14 +45,6 @@ public function __construct(ConcurrentRegion $region) $this->region = $region; } - /** - * {@inheritdoc} - */ - public function getRegion() - { - return $this->region; - } - /** * {@inheritdoc} */ @@ -158,36 +146,4 @@ public function unlockItem(CacheKey $key, Lock $lock) { return $this->region->readUnlock($key, $lock); } - - /** - * {@inheritdoc} - */ - public function get(CacheKey $key) - { - return $this->region->get($key); - } - - /** - * {@inheritdoc} - */ - public function put(CacheKey $key, CacheEntry $entry) - { - return $this->region->put($key, $entry); - } - - /** - * {@inheritdoc} - */ - public function evict(CacheKey $key) - { - return $this->region->evict($key); - } - - /** - * {@inheritdoc} - */ - public function evictAll() - { - return $this->region->evictAll(); - } } diff --git a/lib/Doctrine/ORM/Cache/CacheFactory.php b/lib/Doctrine/ORM/Cache/CacheFactory.php index 6ea5ba25a37..b79d8b8fabb 100644 --- a/lib/Doctrine/ORM/Cache/CacheFactory.php +++ b/lib/Doctrine/ORM/Cache/CacheFactory.php @@ -34,7 +34,7 @@ interface CacheFactory * * @param \Doctrine\ORM\Mapping\ClassMetadata $metadata The entity metadata. * - * @return \Doctrine\ORM\Cache\RegionAccess The built region access. + * @return \Doctrine\ORM\Cache\EntityRegionAccessStrategy The built region access. * * @throws \Doctrine\ORM\Cache\CacheException Indicates problems building the region access. */ @@ -46,7 +46,7 @@ public function buildEntityRegionAccessStrategy(ClassMetadata $metadata); * @param \Doctrine\ORM\Mapping\ClassMetadata $metadata The entity metadata. * @param string $fieldName The field name that represents the association. * - * @return \Doctrine\ORM\Cache\RegionAccess The built region access. + * @return \Doctrine\ORM\Cache\CollectionRegionAccessStrategy The built region access. * * @throws \Doctrine\ORM\Cache\CacheException Indicates problems building the region access. */ diff --git a/lib/Doctrine/ORM/Cache/CollectionRegionAccessStrategy.php b/lib/Doctrine/ORM/Cache/CollectionRegionAccessStrategy.php new file mode 100644 index 00000000000..4c93d6ee746 --- /dev/null +++ b/lib/Doctrine/ORM/Cache/CollectionRegionAccessStrategy.php @@ -0,0 +1,31 @@ +. + */ + +namespace Doctrine\ORM\Cache; + +/** + * Interface for entity region access. + * + * @since 2.5 + * @author Fabio B. Silva + */ +interface CollectionRegionAccessStrategy extends RegionAccessStrategy +{ + +} diff --git a/lib/Doctrine/ORM/Cache/ConcurrentRegionAccess.php b/lib/Doctrine/ORM/Cache/ConcurrentRegionAccessStrategy.php similarity index 96% rename from lib/Doctrine/ORM/Cache/ConcurrentRegionAccess.php rename to lib/Doctrine/ORM/Cache/ConcurrentRegionAccessStrategy.php index d87ab62da0b..22fbe940fb9 100644 --- a/lib/Doctrine/ORM/Cache/ConcurrentRegionAccess.php +++ b/lib/Doctrine/ORM/Cache/ConcurrentRegionAccessStrategy.php @@ -26,7 +26,7 @@ * @since 2.5 * @author Fabio B. Silva */ -interface ConcurrentRegionAccess extends RegionAccess +interface ConcurrentRegionAccessStrategy extends RegionAccessStrategy { /** * We are going to attempt to update/delete the keyed object. @@ -48,4 +48,4 @@ public function lockItem(CacheKey $key); * @throws \Doctrine\ORM\Cache\CacheException */ public function unlockItem(CacheKey $key, Lock $lock); -} +} \ No newline at end of file diff --git a/lib/Doctrine/ORM/Cache/DefaultCacheFactory.php b/lib/Doctrine/ORM/Cache/DefaultCacheFactory.php index f3686fa0cdc..71ea9d4a430 100644 --- a/lib/Doctrine/ORM/Cache/DefaultCacheFactory.php +++ b/lib/Doctrine/ORM/Cache/DefaultCacheFactory.php @@ -26,8 +26,10 @@ use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Cache\Region\DefaultRegion; use Doctrine\Common\Cache\Cache as CacheDriver; -use Doctrine\ORM\Cache\Access\ReadOnlyRegionAccess; -use Doctrine\ORM\Cache\Access\NonStrictReadWriteRegionAccessStrategy; +use Doctrine\ORM\Cache\Access\ReadOnlyEntityRegionAccessStrategy; +use Doctrine\ORM\Cache\Access\ReadOnlyCollectionRegionAccessStrategy; +use Doctrine\ORM\Cache\Access\NonStrictReadWriteEntityRegionAccessStrategy; +use Doctrine\ORM\Cache\Access\NonStrictReadWriteCollectionRegionAccessStrategy; /** * @since 2.5 @@ -60,11 +62,11 @@ public function buildEntityRegionAccessStrategy(ClassMetadata $metadata) $usage = $metadata->cache['usage']; if ($usage === ClassMetadata::CACHE_USAGE_READ_ONLY) { - return new ReadOnlyRegionAccess($this->createRegion($regionName)); + return new ReadOnlyEntityRegionAccessStrategy($this->createRegion($regionName)); } if ($usage === ClassMetadata::CACHE_USAGE_NONSTRICT_READ_WRITE) { - return new NonStrictReadWriteRegionAccessStrategy($this->createRegion($regionName)); + return new NonStrictReadWriteEntityRegionAccessStrategy($this->createRegion($regionName)); } throw new \InvalidArgumentException(sprintf("Unrecognized access strategy type [%s]", $usage)); @@ -80,11 +82,11 @@ public function buildCollectionRegionAccessStrategy(ClassMetadata $metadata, $fi $usage = $mapping['cache']['usage']; if ($usage === ClassMetadata::CACHE_USAGE_READ_ONLY) { - return new ReadOnlyRegionAccess($this->createRegion($regionName)); + return new ReadOnlyCollectionRegionAccessStrategy($this->createRegion($regionName)); } if ($usage === ClassMetadata::CACHE_USAGE_NONSTRICT_READ_WRITE) { - return new NonStrictReadWriteRegionAccessStrategy($this->createRegion($regionName)); + return new NonStrictReadWriteCollectionRegionAccessStrategy($this->createRegion($regionName)); } throw new \InvalidArgumentException(sprintf("Unrecognized access strategy type [%s]", $usage)); diff --git a/lib/Doctrine/ORM/Cache/EntityRegionAccessStrategy.php b/lib/Doctrine/ORM/Cache/EntityRegionAccessStrategy.php new file mode 100644 index 00000000000..2e272eca688 --- /dev/null +++ b/lib/Doctrine/ORM/Cache/EntityRegionAccessStrategy.php @@ -0,0 +1,54 @@ +. + */ + +namespace Doctrine\ORM\Cache; + +/** + * Interface for entity region access. + * + * @since 2.5 + * @author Fabio B. Silva + */ +interface EntityRegionAccessStrategy extends RegionAccessStrategy +{ + /** + * Called after an item has been inserted (after the transaction completes). + * + * @param \Doctrine\ORM\Cache\CacheKey $key The cache key. + * @param \Doctrine\ORM\Cache\CacheEntry $entry The cache entry. + * + * @return boolean TRUE If the contents of the cache actual were changed. + * + * @throws \Doctrine\ORM\Cache\CacheException + */ + public function afterInsert(CacheKey $key, CacheEntry $entry); + + /** + * Called after an item has been updated (after the transaction completes). + * + * @param \Doctrine\ORM\Cache\CacheKey $key The cache key. + * @param \Doctrine\ORM\Cache\CacheEntry $entry The cache entry. + * @param \Doctrine\ORM\Cache\Lock $lock The lock previously obtained from {@link lockItem} + * + * @return boolean TRUE If the contents of the cache actual were changed. + * + * @throws \Doctrine\ORM\Cache\CacheException + */ + public function afterUpdate(CacheKey $key, CacheEntry $entry, Lock $lock = null); +} diff --git a/lib/Doctrine/ORM/Cache/RegionAccess.php b/lib/Doctrine/ORM/Cache/RegionAccessStrategy.php similarity index 70% rename from lib/Doctrine/ORM/Cache/RegionAccess.php rename to lib/Doctrine/ORM/Cache/RegionAccessStrategy.php index 086716d5a74..bc37ad1cb3b 100644 --- a/lib/Doctrine/ORM/Cache/RegionAccess.php +++ b/lib/Doctrine/ORM/Cache/RegionAccessStrategy.php @@ -1,5 +1,4 @@ */ -interface RegionAccess +interface RegionAccessStrategy { /** * Get the wrapped data cache region @@ -58,31 +57,6 @@ public function get(CacheKey $key); */ public function put(CacheKey $key, CacheEntry $entry); - /** - * Called after an item has been inserted (after the transaction completes). - * - * @param \Doctrine\ORM\Cache\CacheKey $key The cache key. - * @param \Doctrine\ORM\Cache\CacheEntry $entry The cache entry. - * - * @return boolean TRUE If the contents of the cache actual were changed. - * - * @throws \Doctrine\ORM\Cache\CacheException - */ - public function afterInsert(CacheKey $key, CacheEntry $entry); - - /** - * Called after an item has been updated (after the transaction completes). - * - * @param \Doctrine\ORM\Cache\CacheKey $key The cache key. - * @param \Doctrine\ORM\Cache\CacheEntry $entry The cache entry. - * @param \Doctrine\ORM\Cache\Lock $lock The lock previously obtained from {@link lockItem} - * - * @return boolean TRUE If the contents of the cache actual were changed. - * - * @throws \Doctrine\ORM\Cache\CacheException - */ - public function afterUpdate(CacheKey $key, CacheEntry $entry, Lock $lock = null); - /** * Forcibly evict an item from the cache immediately without regard for locks. * diff --git a/tests/Doctrine/Tests/ORM/Cache/AbstractEntityRegionAccessTest.php b/tests/Doctrine/Tests/ORM/Cache/AbstractEntityRegionAccessTest.php new file mode 100644 index 00000000000..86c7748bdd2 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Cache/AbstractEntityRegionAccessTest.php @@ -0,0 +1,46 @@ +assertNull($this->regionAccess->get($key1)); + $this->assertNull($this->regionAccess->get($key2)); + + $this->regionAccess->afterInsert($key1, new CacheEntryMock(array('value' => 'foo'))); + $this->regionAccess->afterInsert($key2, new CacheEntryMock(array('value' => 'bar'))); + + $this->assertNotNull($this->regionAccess->get($key1)); + $this->assertNotNull($this->regionAccess->get($key2)); + + $this->assertEquals(new CacheEntryMock(array('value' => 'foo')), $this->regionAccess->get($key1)); + $this->assertEquals(new CacheEntryMock(array('value' => 'bar')), $this->regionAccess->get($key2)); + } + + public function testAfterUpdate() + { + $key1 = new CacheKeyMock('key.1'); + $key2 = new CacheKeyMock('key.2'); + + $this->assertNull($this->regionAccess->get($key1)); + $this->assertNull($this->regionAccess->get($key2)); + + $this->regionAccess->afterUpdate($key1, new CacheEntryMock(array('value' => 'foo'))); + $this->regionAccess->afterUpdate($key2, new CacheEntryMock(array('value' => 'bar'))); + + $this->assertEquals(new CacheEntryMock(array('value' => 'foo')), $this->regionAccess->get($key1)); + $this->assertEquals(new CacheEntryMock(array('value' => 'bar')), $this->regionAccess->get($key2)); + } +} diff --git a/tests/Doctrine/Tests/ORM/Cache/AbstractRegionAccessTest.php b/tests/Doctrine/Tests/ORM/Cache/AbstractRegionAccessTest.php index 0be3bccef76..3e8888ffef0 100644 --- a/tests/Doctrine/Tests/ORM/Cache/AbstractRegionAccessTest.php +++ b/tests/Doctrine/Tests/ORM/Cache/AbstractRegionAccessTest.php @@ -3,18 +3,17 @@ namespace Doctrine\Tests\ORM\Cache; use Doctrine\ORM\Cache\Region; +use Doctrine\Tests\OrmTestCase; use Doctrine\Common\Cache\Cache; use Doctrine\Common\Cache\ArrayCache; use Doctrine\Tests\Mocks\CacheKeyMock; use Doctrine\Tests\Mocks\CacheEntryMock; use Doctrine\ORM\Cache\Region\DefaultRegion; -require_once __DIR__ . '/../../TestInit.php'; - /** * @group DDC-2183 */ -abstract class AbstractRegionAccessTest extends \Doctrine\Tests\OrmTestCase +abstract class AbstractRegionAccessTest extends OrmTestCase { /** * @var \Doctrine\Common\Cache\Cache @@ -116,37 +115,4 @@ public function testEvictAll() $this->assertNull($this->regionAccess->get($key1)); $this->assertNull($this->regionAccess->get($key2)); } - - public function testAfterInsert() - { - $key1 = new CacheKeyMock('key.1'); - $key2 = new CacheKeyMock('key.2'); - - $this->assertNull($this->regionAccess->get($key1)); - $this->assertNull($this->regionAccess->get($key2)); - - $this->regionAccess->afterInsert($key1, new CacheEntryMock(array('value' => 'foo'))); - $this->regionAccess->afterInsert($key2, new CacheEntryMock(array('value' => 'bar'))); - - $this->assertNotNull($this->regionAccess->get($key1)); - $this->assertNotNull($this->regionAccess->get($key2)); - - $this->assertEquals(new CacheEntryMock(array('value' => 'foo')), $this->regionAccess->get($key1)); - $this->assertEquals(new CacheEntryMock(array('value' => 'bar')), $this->regionAccess->get($key2)); - } - - public function testAfterUpdate() - { - $key1 = new CacheKeyMock('key.1'); - $key2 = new CacheKeyMock('key.2'); - - $this->assertNull($this->regionAccess->get($key1)); - $this->assertNull($this->regionAccess->get($key2)); - - $this->regionAccess->afterUpdate($key1, new CacheEntryMock(array('value' => 'foo'))); - $this->regionAccess->afterUpdate($key2, new CacheEntryMock(array('value' => 'bar'))); - - $this->assertEquals(new CacheEntryMock(array('value' => 'foo')), $this->regionAccess->get($key1)); - $this->assertEquals(new CacheEntryMock(array('value' => 'bar')), $this->regionAccess->get($key2)); - } } diff --git a/tests/Doctrine/Tests/ORM/Cache/DefaultCacheTest.php b/tests/Doctrine/Tests/ORM/Cache/DefaultCacheTest.php index d1f406ddfeb..be75cc47ae8 100644 --- a/tests/Doctrine/Tests/ORM/Cache/DefaultCacheTest.php +++ b/tests/Doctrine/Tests/ORM/Cache/DefaultCacheTest.php @@ -75,13 +75,13 @@ public function testImplementsCache() public function testGetEntityCacheRegionAccess() { - $this->assertInstanceOf('Doctrine\ORM\Cache\RegionAccess', $this->cache->getEntityCacheRegionAccess(State::CLASSNAME)); + $this->assertInstanceOf('Doctrine\ORM\Cache\RegionAccessStrategy', $this->cache->getEntityCacheRegionAccess(State::CLASSNAME)); $this->assertNull($this->cache->getEntityCacheRegionAccess(self::NON_CACHEABLE_ENTITY)); } public function testGetCollectionCacheRegionAccess() { - $this->assertInstanceOf('Doctrine\ORM\Cache\RegionAccess', $this->cache->getCollectionCacheRegionAccess(State::CLASSNAME, 'cities')); + $this->assertInstanceOf('Doctrine\ORM\Cache\RegionAccessStrategy', $this->cache->getCollectionCacheRegionAccess(State::CLASSNAME, 'cities')); $this->assertNull($this->cache->getCollectionCacheRegionAccess(self::NON_CACHEABLE_ENTITY, 'phonenumbers')); } diff --git a/tests/Doctrine/Tests/ORM/Cache/DefaultQueryCacheTest.php b/tests/Doctrine/Tests/ORM/Cache/DefaultQueryCacheTest.php index 87e74cbefbd..33d1b199b81 100644 --- a/tests/Doctrine/Tests/ORM/Cache/DefaultQueryCacheTest.php +++ b/tests/Doctrine/Tests/ORM/Cache/DefaultQueryCacheTest.php @@ -40,7 +40,7 @@ class DefaultQueryCacheTest extends OrmTestCase private $region; /** - * @var \Doctrine\ORM\Cache\Access\ConcurrentRegionAccessStrategy\CacheFactorySecondLevelCacheConcurrentTest + * @var \Doctrine\Tests\ORM\Cache\CacheFactoryDefaultQueryCacheTest */ private $cacheFactory; @@ -518,12 +518,12 @@ public function __construct(DefaultQueryCache $queryCache, CacheRegionMock $regi public function buildEntityRegionAccessStrategy(ClassMetadata $metadata) { - return new \Doctrine\ORM\Cache\Access\NonStrictReadWriteRegionAccessStrategy($this->region); + return new \Doctrine\ORM\Cache\Access\NonStrictReadWriteEntityRegionAccessStrategy($this->region); } public function buildCollectionRegionAccessStrategy(ClassMetadata $metadata, $fieldName) { - return new \Doctrine\ORM\Cache\Access\NonStrictReadWriteRegionAccessStrategy($this->region); + return new \Doctrine\ORM\Cache\Access\NonStrictReadWriteCollectionRegionAccessStrategy($this->region); } public function buildQueryCache(EntityManagerInterface $em, $regionName = null) diff --git a/tests/Doctrine/Tests/ORM/Cache/NonStrictReadWriteCollectionRegionAccessStrategyTest.php b/tests/Doctrine/Tests/ORM/Cache/NonStrictReadWriteCollectionRegionAccessStrategyTest.php new file mode 100644 index 00000000000..47e7b91934f --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Cache/NonStrictReadWriteCollectionRegionAccessStrategyTest.php @@ -0,0 +1,17 @@ +cache['region']; $region = $this->createRegion($regionName); - $access = new ConcurrentRegionAccessStrategy($region); + $access = new ReadWriteEntityRegionAccessStrategy($region); return $access; } @@ -260,7 +260,7 @@ public function buildCollectionRegionAccessStrategy(ClassMetadata $metadata, $fi $mapping = $metadata->getAssociationMapping($fieldName); $regionName = $mapping['cache']['region']; $region = $this->createRegion($regionName); - $access = new ConcurrentRegionAccessStrategy($region); + $access = new ReadWriteCollectionRegionAccessStrategy($region); return $access; } diff --git a/tests/travis/mysql.travis.xml b/tests/travis/mysql.travis.xml index 9177e2f51fa..e278e88596d 100644 --- a/tests/travis/mysql.travis.xml +++ b/tests/travis/mysql.travis.xml @@ -1,5 +1,5 @@ - + diff --git a/tests/travis/pgsql.travis.xml b/tests/travis/pgsql.travis.xml index 1280d95c852..a2993fcb173 100644 --- a/tests/travis/pgsql.travis.xml +++ b/tests/travis/pgsql.travis.xml @@ -1,5 +1,5 @@ - + diff --git a/tests/travis/sqlite.travis.xml b/tests/travis/sqlite.travis.xml index 7dbe99fe1bf..242d4dea8c4 100644 --- a/tests/travis/sqlite.travis.xml +++ b/tests/travis/sqlite.travis.xml @@ -1,5 +1,5 @@ - +