. */ namespace Doctrine\ORM\Cache\Persister; use Doctrine\ORM\Cache\CollectionCacheKey; use Doctrine\ORM\PersistentCollection; /** * @author Fabio B. Silva * @since 2.5 */ class NonStrictReadWriteCachedCollectionPersister extends AbstractCollectionPersister { /** * {@inheritdoc} */ public function afterTransactionComplete() { if (isset($this->queuedCache['update'])) { foreach ($this->queuedCache['update'] as $item) { $this->storeCollectionCache($item['key'], $item['list']); } } if (isset($this->queuedCache['delete'])) { foreach ($this->queuedCache['delete'] as $key) { $this->region->evict($key); } } $this->queuedCache = array(); } /** * {@inheritdoc} */ public function afterTransactionRolledBack() { $this->queuedCache = array(); } /** * {@inheritdoc} */ public function delete(PersistentCollection $collection) { $ownerId = $this->uow->getEntityIdentifier($collection->getOwner()); $key = new CollectionCacheKey($this->sourceEntity->rootEntityName, $this->association['fieldName'], $ownerId); $this->persister->delete($collection); $this->queuedCache['delete'][spl_object_hash($collection)] = $key; } /** * {@inheritdoc} */ public function update(PersistentCollection $collection) { $isInitialized = $collection->isInitialized(); $isDirty = $collection->isDirty(); if ( ! $isInitialized && ! $isDirty) { return; } $ownerId = $this->uow->getEntityIdentifier($collection->getOwner()); $key = new CollectionCacheKey($this->sourceEntity->rootEntityName, $this->association['fieldName'], $ownerId); // Invalidate non initialized collections OR ordered collection if ($isDirty && ! $isInitialized || isset($this->association['orderBy'])) { $this->persister->update($collection); $this->queuedCache['delete'][spl_object_hash($collection)] = $key; return; } $this->persister->update($collection); $this->queuedCache['update'][spl_object_hash($collection)] = array( 'key' => $key, 'list' => $collection ); } }