/** * {@inheritdoc} */ public function storeCollectionCache(CollectionCacheKey $key, $elements) { /* @var $targetPersister CachedEntityPersister */ $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 => $entityKey) { 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); } }
/** * {@inheritdoc} */ public function storeCollectionCache(CollectionCacheKey $key, $elements) { /* @var $targetPersister CachedEntityPersister */ $associationMapping = $this->sourceEntity->associationMappings[$key->association]; $targetPersister = $this->uow->getEntityPersister($this->targetEntity->rootEntityName); $targetRegion = $targetPersister->getCacheRegion(); $targetHydrator = $targetPersister->getEntityHydrator(); // Only preserve ordering if association configured it if (!(isset($associationMapping['indexBy']) && $associationMapping['indexBy'])) { // Elements may be an array or a Collection $elements = array_values(is_array($elements) ? $elements : $elements->getValues()); } $entry = $this->hydrator->buildCacheEntry($this->targetEntity, $key, $elements); foreach ($entry->identifiers as $index => $entityKey) { 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); } }