public function testEvictAll()
 {
     $key1 = new CacheKeyMock('key.1');
     $key2 = new CacheKeyMock('key.2');
     $this->assertFalse($this->region->contains($key1));
     $this->assertFalse($this->region->contains($key2));
     $this->region->put($key1, new CacheEntryMock(array('value' => 'foo')));
     $this->region->put($key2, new CacheEntryMock(array('value' => 'bar')));
     $this->assertTrue($this->region->contains($key1));
     $this->assertTrue($this->region->contains($key2));
     $this->region->evictAll();
     $this->assertFalse($this->region->contains($key1));
     $this->assertFalse($this->region->contains($key2));
 }
 /**
  * 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 count(PersistentCollection $collection)
 {
     $ownerId = $this->uow->getEntityIdentifier($collection->getOwner());
     $key = new CollectionCacheKey($this->sourceEntity->rootEntityName, $this->association['fieldName'], $ownerId);
     $entry = $this->region->get($key);
     if ($entry !== null) {
         return count($entry->identifiers);
     }
     return $this->persister->count($collection);
 }
 /**
  * {@inheritdoc}
  */
 public function put(CacheKey $key, CacheEntry $entry, Lock $lock = null)
 {
     $this->calls[__FUNCTION__][] = array('key' => $key, 'entry' => $entry);
     $this->throwException(__FUNCTION__);
     if (isset($this->locks[$key->hash])) {
         if ($lock !== null && $this->locks[$key->hash]->value === $lock->value) {
             return $this->region->put($key, $entry);
         }
         return false;
     }
     return $this->region->put($key, $entry);
 }
 /**
  * {@inheritdoc}
  */
 public function loadById(array $identifier, $entity = null)
 {
     $cacheKey = new EntityCacheKey($this->class->rootEntityName, $identifier);
     $cacheEntry = $this->region->get($cacheKey);
     $class = $this->class;
     if ($cacheEntry !== null) {
         if ($cacheEntry->class !== $this->class->name) {
             $class = $this->metadataFactory->getMetadataFor($cacheEntry->class);
         }
         if (($entity = $this->hydrator->loadCacheEntry($class, $cacheKey, $cacheEntry, $entity)) !== null) {
             if ($this->cacheLogger) {
                 $this->cacheLogger->entityCacheHit($this->regionName, $cacheKey);
             }
             return $entity;
         }
     }
     $entity = $this->persister->loadById($identifier, $entity);
     if ($entity === null) {
         return null;
     }
     $class = $this->class;
     $className = ClassUtils::getClass($entity);
     if ($className !== $this->class->name) {
         $class = $this->metadataFactory->getMetadataFor($className);
     }
     $cacheEntry = $this->hydrator->buildCacheEntry($class, $cacheKey, $entity);
     $cached = $this->region->put($cacheKey, $cacheEntry);
     if ($cached && ($this->joinedAssociations === null || count($this->joinedAssociations) > 0)) {
         $this->storeJoinedAssociations($entity);
     }
     if ($this->cacheLogger) {
         if ($cached) {
             $this->cacheLogger->entityCachePut($this->regionName, $cacheKey);
         }
         $this->cacheLogger->entityCacheMiss($this->regionName, $cacheKey);
     }
     return $entity;
 }
 /**
  * {@inheritdoc}
  */
 public function clear()
 {
     return $this->region->evictAll();
 }
Example #7
0
 /**
  * @param \Doctrine\ORM\Cache\Region $region
  */
 public function setRegion(Region $region)
 {
     $this->regions[$region->getName()] = $region;
 }