/** * {@inheritdoc} */ public function storeCollectionCache(CollectionCacheKey $key, $elements) { $targetPersister = $this->uow->getEntityPersister($this->targetEntity->rootEntityName); $targetRegion = $targetPersister->getCacheRegion(); $targetHydrator = $targetPersister->getEntityHydrator(); $entry = $this->hydrator->buildCacheEntry($this->targetEntity, $key, $elements); foreach ($entry->identifiers as $index => $identifier) { $entityKey = new EntityCacheKey($this->targetEntity->rootEntityName, $identifier); if ($targetRegion->contains($entityKey)) { continue; } $class = $this->targetEntity; $className = ClassUtils::getClass($elements[$index]); if ($className !== $this->targetEntity->name) { $class = $this->metadataFactory->getMetadataFor($className); } $entity = $elements[$index]; $entityEntry = $targetHydrator->buildCacheEntry($class, $entityKey, $entity); $targetRegion->put($entityKey, $entityEntry); } $cached = $this->region->put($key, $entry); if ($this->cacheLogger && $cached) { $this->cacheLogger->collectionCachePut($this->regionName, $key); } }
/** * Clears cache entries related to the current collection * * @param PersistentCollection $collection */ protected function evictCollectionCache(PersistentCollection $collection) { $key = new CollectionCacheKey($this->sourceEntity->rootEntityName, $this->association['fieldName'], $this->uow->getEntityIdentifier($collection->getOwner())); $this->region->evict($key); if ($this->cacheLogger) { $this->cacheLogger->collectionCachePut($this->regionName, $key); } }