diff --git a/docs/en/reference/second-level-cache.rst b/docs/en/reference/second-level-cache.rst index bf7153612bc..f2643af5c0b 100644 --- a/docs/en/reference/second-level-cache.rst +++ b/docs/en/reference/second-level-cache.rst @@ -31,31 +31,31 @@ Each cache region resides in a specific cache namespace and has its own lifetime Notice that when caching collection and queries only identifiers are stored. The entity values will be stored in its own region -Something like below for an entity region : +Something like below for an entity region: .. code-block:: php ['id'=> 1, 'name' => 'FooBar', 'associationName'=>null], - 'region_name:entity_2_hash' => ['id'=> 2, 'name' => 'Foo', 'associationName'=>['id'=>11]], - 'region_name:entity_3_hash' => ['id'=> 3, 'name' => 'Bar', 'associationName'=>['id'=>22]] + 'region_name:entity_1_hash' => ['id' => 1, 'name' => 'FooBar', 'associationName' => null], + 'region_name:entity_2_hash' => ['id' => 2, 'name' => 'Foo', 'associationName' => ['id' => 11]], + 'region_name:entity_3_hash' => ['id' => 3, 'name' => 'Bar', 'associationName' => ['id' => 22]] ]; If the entity holds a collection that also needs to be cached. -An collection region could look something like : +An collection region could look something like: .. code-block:: php ['ownerId'=> 1, 'list' => [1, 2, 3]], - 'region_name:entity_2_coll_assoc_name_hash' => ['ownerId'=> 2, 'list' => [2, 3]], - 'region_name:entity_3_coll_assoc_name_hash' => ['ownerId'=> 3, 'list' => [2, 4]] + 'region_name:entity_1_coll_assoc_name_hash' => ['ownerId' => 1, 'list' => [1, 2, 3]], + 'region_name:entity_2_coll_assoc_name_hash' => ['ownerId' => 2, 'list' => [2, 3]], + 'region_name:entity_3_coll_assoc_name_hash' => ['ownerId' => 3, 'list' => [2, 4]] ]; -A query region might be something like : +A query region might be something like: .. code-block:: php @@ -93,8 +93,6 @@ Cache region ``Doctrine\ORM\Cache\Region`` defines a contract for accessing a particular cache region. -`See API Doc `_. - Concurrent cache region ~~~~~~~~~~~~~~~~~~~~~~~ @@ -105,8 +103,6 @@ If you want to use an ``READ_WRITE`` cache, you should consider providing your o ``Doctrine\ORM\Cache\ConcurrentRegion`` defines a contract for concurrently managed data region. -`See API Doc `_. - Timestamp region ~~~~~~~~~~~~~~~~ @@ -114,8 +110,6 @@ Timestamp region Tracks the timestamps of the most recent updates to particular entity. -`See API Doc `_. - .. _reference-second-level-cache-mode: Caching mode @@ -132,7 +126,7 @@ Caching mode * Read Write Cache doesn’t employ any locks but can do reads, inserts, updates and deletes. * Good if the application needs to update data rarely. - + * ``READ_WRITE`` @@ -147,21 +141,21 @@ Built-in cached persisters Cached persisters are responsible to access cache regions. - +-----------------------+-------------------------------------------------------------------------------------------+ - | Cache Usage | Persister | - +=======================+===========================================================================================+ - | READ_ONLY | Doctrine\\ORM\\Cache\\Persister\\Entity\\ReadOnlyCachedEntityPersister | - +-----------------------+-------------------------------------------------------------------------------------------+ - | READ_WRITE | Doctrine\\ORM\\Cache\\Persister\\Entity\\ReadWriteCachedEntityPersister | - +-----------------------+-------------------------------------------------------------------------------------------+ - | NONSTRICT_READ_WRITE | Doctrine\\ORM\\Cache\\Persister\\Entity\\NonStrictReadWriteCachedEntityPersister | - +-----------------------+-------------------------------------------------------------------------------------------+ - | READ_ONLY | Doctrine\\ORM\\Cache\\Persister\\Collection\\ReadOnlyCachedCollectionPersister | - +-----------------------+-------------------------------------------------------------------------------------------+ - | READ_WRITE | Doctrine\\ORM\\Cache\\Persister\\Collection\\ReadWriteCachedCollectionPersister | - +-----------------------+-------------------------------------------------------------------------------------------+ - | NONSTRICT_READ_WRITE | Doctrine\\ORM\\Cache\\Persister\\Collection\\NonStrictReadWriteCachedCollectionPersister | - +-----------------------+-------------------------------------------------------------------------------------------+ + +-----------------------+------------------------------------------------------------------------------------------+ + | Cache Usage | Persister | + +=======================+==========================================================================================+ + | READ_ONLY | ``Doctrine\ORM\Cache\Persister\Entity\ReadOnlyCachedEntityPersister`` | + +-----------------------+------------------------------------------------------------------------------------------+ + | READ_WRITE | ``Doctrine\ORM\Cache\Persister\Entity\ReadWriteCachedEntityPersister`` | + +-----------------------+------------------------------------------------------------------------------------------+ + | NONSTRICT_READ_WRITE | ``Doctrine\ORM\Cache\Persister\Entity\NonStrictReadWriteCachedEntityPersister`` | + +-----------------------+------------------------------------------------------------------------------------------+ + | READ_ONLY | ``Doctrine\ORM\Cache\Persister\Collection\ReadOnlyCachedCollectionPersister`` | + +-----------------------+------------------------------------------------------------------------------------------+ + | READ_WRITE | ``Doctrine\ORM\Cache\Persister\Collection\ReadWriteCachedCollectionPersister`` | + +-----------------------+------------------------------------------------------------------------------------------+ + | NONSTRICT_READ_WRITE | ``Doctrine\ORM\Cache\Persister\Collection\NonStrictReadWriteCachedCollectionPersister`` | + +-----------------------+------------------------------------------------------------------------------------------+ Configuration ------------- @@ -172,7 +166,7 @@ Enable Second Level Cache ~~~~~~~~~~~~~~~~~~~~~~~~~ To enable the second-level-cache, you should provide a cache factory. -``\Doctrine\ORM\Cache\DefaultCacheFactory`` is the default implementation. +``Doctrine\ORM\Cache\DefaultCacheFactory`` is the default implementation. .. code-block:: php @@ -196,7 +190,7 @@ Cache Factory Cache Factory is the main point of extension. -It allows you to provide a specific implementation of the following components : +It allows you to provide a specific implementation of the following components: ``QueryCache`` stores and retrieves query cache results. @@ -209,8 +203,6 @@ It allows you to provide a specific implementation of the following components : ``CollectionHydrator`` transforms collections into cache entries and cache entries into collections -`See API Doc `_. - Region Lifetime ~~~~~~~~~~~~~~~ @@ -234,7 +226,7 @@ Cache Log ~~~~~~~~~ By providing a cache logger you should be able to get information about all cache operations such as hits, misses and puts. -``\Doctrine\ORM\Cache\Logging\StatisticsCacheLogger`` is a built-in implementation that provides basic statistics. +``Doctrine\ORM\Cache\Logging\StatisticsCacheLogger`` is a built-in implementation that provides basic statistics. .. code-block:: php @@ -269,12 +261,9 @@ By providing a cache logger you should be able to get information about all cach $logger->getMissCount(); If you want to get more information you should implement -``\Doctrine\ORM\Cache\Logging\CacheLogger`` and collect +``Doctrine\ORM\Cache\Logging\CacheLogger`` and collect all the information you want. -`See API Doc `_. - - Entity cache definition ----------------------- * Entity cache configuration allows you to define the caching strategy and region for an entity. @@ -330,8 +319,8 @@ level cache region. Country: type: entity cache: - usage : READ_ONLY - region : my_entity_region + usage: READ_ONLY + region: my_entity_region id: id: type: integer @@ -401,7 +390,7 @@ It caches the primary keys of association and cache each element will be cached - + @@ -421,7 +410,7 @@ It caches the primary keys of association and cache each element will be cached State: type: entity cache: - usage : NONSTRICT_READ_WRITE + usage: NONSTRICT_READ_WRITE id: id: type: integer @@ -439,17 +428,18 @@ It caches the primary keys of association and cache each element will be cached country_id: referencedColumnName: id cache: - usage : NONSTRICT_READ_WRITE + usage: NONSTRICT_READ_WRITE oneToMany: cities: targetEntity:City mappedBy: state cache: - usage : NONSTRICT_READ_WRITE + usage: NONSTRICT_READ_WRITE +.. note:: -> Note: for this to work, the target entity must also be marked as cacheable. + for this to work, the target entity must also be marked as cacheable. Cache usage ~~~~~~~~~~~ @@ -466,8 +456,8 @@ Basic entity cache $country1 = $em->find('Country', 1); // Retrieve item from cache - $country1->setName("New Name"); - + $country1->setName('New Name'); + $em->flush(); // Hit database to update the row and update cache $em->clear(); // Clear entity manager @@ -492,7 +482,7 @@ Association cache $state = $em->find('State', 1); // Hit database to update the row and update cache entry - $state->setName("New Name"); + $state->setName('New Name'); $em->persist($state); $em->flush(); @@ -550,7 +540,7 @@ The query cache stores the results of the query but as identifiers, entity value ->setCacheable(true) ->getResult(); - $em->clear() + $em->clear(); // Check if query result is valid and load entities from cache $result2 = $em->createQuery('SELECT c FROM Country c ORDER BY c.name') @@ -573,7 +563,7 @@ The Cache Mode controls how a particular query interacts with the second-level c /* @var $em \Doctrine\ORM\EntityManager */ // Will refresh the query cache and all entities the cache as it reads from the database. $result1 = $em->createQuery('SELECT c FROM Country c ORDER BY c.name') - ->setCacheMode(Cache::MODE_GET) + ->setCacheMode(\Doctrine\ORM\Cache::MODE_GET) ->setCacheable(true) ->getResult(); @@ -597,7 +587,7 @@ Execute the ``UPDATE`` and invalidate ``all cache entries`` using ``Query::HINT_ _em->createQuery("UPDATE Entity\Country u SET u.name = 'unknown' WHERE u.id = 1") - ->setHint(Query::HINT_CACHE_EVICT, true) + ->setHint(\Doctrine\ORM\Query::HINT_CACHE_EVICT, true) ->execute(); @@ -712,11 +702,11 @@ For performance reasons the cache API does not extract from composite primary ke $article = $em->find('Article', $article); // Supported - $id = array('source' => 1, 'target' => 2); + $id = ['source' => 1, 'target' => 2]; $reference = $em->find('Reference', $id); // NOT Supported - $id = array('source' => new Article(1), 'target' => new Article(2)); + $id = ['source' => new Article(1), 'target' => new Article(2)]; $reference = $em->find('Reference', $id); Distributed environments diff --git a/lib/Doctrine/ORM/Tools/SchemaValidator.php b/lib/Doctrine/ORM/Tools/SchemaValidator.php index c8535b42a88..db27180cdc9 100644 --- a/lib/Doctrine/ORM/Tools/SchemaValidator.php +++ b/lib/Doctrine/ORM/Tools/SchemaValidator.php @@ -239,7 +239,7 @@ public function validateClass(ClassMetadataInfo $class) } } - if (! $class->isInheritanceTypeNone() && ! $class->isRootEntity() && ! $class->reflClass->isAbstract() && ! $class->isMappedSuperclass && array_search($class->name, $class->discriminatorMap, true) === false) { + if (! $class->isInheritanceTypeNone() && ! $class->isRootEntity() && ! $class->isMappedSuperclass && array_search($class->name, $class->discriminatorMap, true) === false) { $ce[] = "Entity class '" . $class->name . "' is part of inheritance hierarchy, but is " . "not mapped in the root entity '" . $class->rootEntityName . "' discriminator map. " . 'All subclasses must be listed in the discriminator map.'; diff --git a/tests/Doctrine/Tests/ORM/Tools/SchemaValidatorTest.php b/tests/Doctrine/Tests/ORM/Tools/SchemaValidatorTest.php index 2c5ea7b4907..58c5aca7f76 100644 --- a/tests/Doctrine/Tests/ORM/Tools/SchemaValidatorTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/SchemaValidatorTest.php @@ -225,17 +225,6 @@ public function testMappedSuperclassNotPresentInDiscriminator(): void $this->assertEquals([], $ce); } - - /** - * @group 9095 - */ - public function testAbstractChildClassNotPresentInDiscriminator(): void - { - $class1 = $this->em->getClassMetadata(Issue9095AbstractChild::class); - $ce = $this->validator->validateClass($class1); - - $this->assertEquals([], $ce); - } } /** @@ -267,35 +256,6 @@ class ChildEntity extends MappedSuperclassEntity { } -/** - * @Entity - * @InheritanceType("SINGLE_TABLE") - * @DiscriminatorMap({"child" = Issue9095Child::class}) - */ -abstract class Issue9095Parent -{ - /** - * @var mixed - * @Id - * @Column - */ - protected $key; -} - -/** - * @Entity - */ -abstract class Issue9095AbstractChild extends Issue9095Parent -{ -} - -/** - * @Entity - */ -class Issue9095Child extends Issue9095AbstractChild -{ -} - /** * @Entity */