mailpoet
/
vendor-prefixed
/
doctrine
/
orm
/
src
/
Cache
/
Persister
/
Collection
/
NonStrictReadWriteCachedCollectionPersister.php
AbstractCollectionPersister.php
9 months ago
CachedCollectionPersister.php
9 months ago
NonStrictReadWriteCachedCollectionPersister.php
9 months ago
ReadOnlyCachedCollectionPersister.php
9 months ago
ReadWriteCachedCollectionPersister.php
9 months ago
index.php
9 months ago
NonStrictReadWriteCachedCollectionPersister.php
54 lines
| 1 | <?php |
| 2 | declare (strict_types=1); |
| 3 | namespace MailPoetVendor\Doctrine\ORM\Cache\Persister\Collection; |
| 4 | if (!defined('ABSPATH')) exit; |
| 5 | use MailPoetVendor\Doctrine\ORM\Cache\CollectionCacheKey; |
| 6 | use MailPoetVendor\Doctrine\ORM\PersistentCollection; |
| 7 | use function spl_object_id; |
| 8 | class NonStrictReadWriteCachedCollectionPersister extends AbstractCollectionPersister |
| 9 | { |
| 10 | public function afterTransactionComplete() |
| 11 | { |
| 12 | if (isset($this->queuedCache['update'])) { |
| 13 | foreach ($this->queuedCache['update'] as $item) { |
| 14 | $this->storeCollectionCache($item['key'], $item['list']); |
| 15 | } |
| 16 | } |
| 17 | if (isset($this->queuedCache['delete'])) { |
| 18 | foreach ($this->queuedCache['delete'] as $key) { |
| 19 | $this->region->evict($key); |
| 20 | } |
| 21 | } |
| 22 | $this->queuedCache = []; |
| 23 | } |
| 24 | public function afterTransactionRolledBack() |
| 25 | { |
| 26 | $this->queuedCache = []; |
| 27 | } |
| 28 | public function delete(PersistentCollection $collection) |
| 29 | { |
| 30 | $ownerId = $this->uow->getEntityIdentifier($collection->getOwner()); |
| 31 | $key = new CollectionCacheKey($this->sourceEntity->rootEntityName, $this->association['fieldName'], $ownerId, $this->filters->getHash()); |
| 32 | $this->persister->delete($collection); |
| 33 | $this->queuedCache['delete'][spl_object_id($collection)] = $key; |
| 34 | } |
| 35 | public function update(PersistentCollection $collection) |
| 36 | { |
| 37 | $isInitialized = $collection->isInitialized(); |
| 38 | $isDirty = $collection->isDirty(); |
| 39 | if (!$isInitialized && !$isDirty) { |
| 40 | return; |
| 41 | } |
| 42 | $ownerId = $this->uow->getEntityIdentifier($collection->getOwner()); |
| 43 | $key = new CollectionCacheKey($this->sourceEntity->rootEntityName, $this->association['fieldName'], $ownerId, $this->filters->getHash()); |
| 44 | // Invalidate non initialized collections OR ordered collection |
| 45 | if ($isDirty && !$isInitialized || isset($this->association['orderBy'])) { |
| 46 | $this->persister->update($collection); |
| 47 | $this->queuedCache['delete'][spl_object_id($collection)] = $key; |
| 48 | return; |
| 49 | } |
| 50 | $this->persister->update($collection); |
| 51 | $this->queuedCache['update'][spl_object_id($collection)] = ['key' => $key, 'list' => $collection]; |
| 52 | } |
| 53 | } |
| 54 |