Exemplo n.º 1
0
 /**
  * @dataProvider dataProviderCacheValues
  */
 public function testPutGetContainsEvict($key, $value)
 {
     $this->assertFalse($this->region->contains($key));
     $this->region->put($key, $value);
     $this->assertTrue($this->region->contains($key));
     $actual = $this->region->get($key);
     $this->assertEquals($value, $actual);
     $this->region->evict($key);
     $this->assertFalse($this->region->contains($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);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function get(QueryCacheKey $key, ResultSetMapping $rsm, array $hints = array())
 {
     if (!($key->cacheMode & Cache::MODE_GET)) {
         return null;
     }
     $entry = $this->region->get($key);
     if (!$entry instanceof QueryCacheEntry) {
         return null;
     }
     if (!$this->validator->isValid($key, $entry)) {
         $this->region->evict($key);
         return null;
     }
     $result = array();
     $entityName = reset($rsm->aliasMap);
     $hasRelation = !empty($rsm->relationMap);
     $persister = $this->uow->getEntityPersister($entityName);
     $region = $persister->getCacheRegion();
     $regionName = $region->getName();
     // @TODO - move to cache hydration component
     foreach ($entry->result as $index => $entry) {
         if (($entityEntry = $region->get($entityKey = new EntityCacheKey($entityName, $entry['identifier']))) === null) {
             if ($this->cacheLogger !== null) {
                 $this->cacheLogger->entityCacheMiss($regionName, $entityKey);
             }
             return null;
         }
         if ($this->cacheLogger !== null) {
             $this->cacheLogger->entityCacheHit($regionName, $entityKey);
         }
         if (!$hasRelation) {
             $result[$index] = $this->uow->createEntity($entityEntry->class, $entityEntry->resolveAssociationEntries($this->em), self::$hints);
             continue;
         }
         $data = $entityEntry->data;
         foreach ($entry['associations'] as $name => $assoc) {
             $assocPersister = $this->uow->getEntityPersister($assoc['targetEntity']);
             $assocRegion = $assocPersister->getCacheRegion();
             if ($assoc['type'] & ClassMetadata::TO_ONE) {
                 if (($assocEntry = $assocRegion->get($assocKey = new EntityCacheKey($assoc['targetEntity'], $assoc['identifier']))) === null) {
                     if ($this->cacheLogger !== null) {
                         $this->cacheLogger->entityCacheMiss($assocRegion->getName(), $assocKey);
                     }
                     $this->uow->hydrationComplete();
                     return null;
                 }
                 $data[$name] = $this->uow->createEntity($assocEntry->class, $assocEntry->resolveAssociationEntries($this->em), self::$hints);
                 if ($this->cacheLogger !== null) {
                     $this->cacheLogger->entityCacheHit($assocRegion->getName(), $assocKey);
                 }
                 continue;
             }
             if (!isset($assoc['list']) || empty($assoc['list'])) {
                 continue;
             }
             $targetClass = $this->em->getClassMetadata($assoc['targetEntity']);
             $collection = new PersistentCollection($this->em, $targetClass, new ArrayCollection());
             foreach ($assoc['list'] as $assocIndex => $assocId) {
                 if (($assocEntry = $assocRegion->get($assocKey = new EntityCacheKey($assoc['targetEntity'], $assocId))) === null) {
                     if ($this->cacheLogger !== null) {
                         $this->cacheLogger->entityCacheMiss($assocRegion->getName(), $assocKey);
                     }
                     $this->uow->hydrationComplete();
                     return null;
                 }
                 $element = $this->uow->createEntity($assocEntry->class, $assocEntry->resolveAssociationEntries($this->em), self::$hints);
                 $collection->hydrateSet($assocIndex, $element);
                 if ($this->cacheLogger !== null) {
                     $this->cacheLogger->entityCacheHit($assocRegion->getName(), $assocKey);
                 }
             }
             $data[$name] = $collection;
             $collection->setInitialized(true);
         }
         $result[$index] = $this->uow->createEntity($entityEntry->class, $data, self::$hints);
     }
     $this->uow->hydrationComplete();
     return $result;
 }
Exemplo n.º 4
0
 /**
  * {@inheritdoc}
  */
 public function evict(CacheKey $key)
 {
     $this->calls[__FUNCTION__][] = array('key' => $key);
     $this->throwException(__FUNCTION__);
     return $this->region->evict($key);
 }