/**
  * {@inheritdoc}
  */
 public function loadCriteria(Criteria $criteria)
 {
     $orderBy = $criteria->getOrderings();
     $limit = $criteria->getMaxResults();
     $offset = $criteria->getFirstResult();
     $query = $this->persister->getSelectSQL($criteria);
     $hash = $this->getHash($query, $criteria, $orderBy, $limit, $offset);
     $rsm = $this->getResultSetMapping();
     $queryKey = new QueryCacheKey($hash, 0, Cache::MODE_NORMAL, $this->timestampKey);
     $queryCache = $this->cache->getQueryCache($this->regionName);
     $cacheResult = $queryCache->get($queryKey, $rsm);
     if ($cacheResult !== null) {
         if ($this->cacheLogger) {
             $this->cacheLogger->queryCacheHit($this->regionName, $queryKey);
         }
         return $cacheResult;
     }
     $result = $this->persister->loadCriteria($criteria);
     $cached = $queryCache->put($queryKey, $rsm, $result);
     if ($this->cacheLogger) {
         if ($result) {
             $this->cacheLogger->queryCacheMiss($this->regionName, $queryKey);
         }
         if ($cached) {
             $this->cacheLogger->queryCachePut($this->regionName, $queryKey);
         }
     }
     return $result;
 }
 /**
  * {@inheritdoc}
  */
 public function loadCriteria(Criteria $criteria)
 {
     $query = $this->persister->getSelectSQL($criteria);
     $timestamp = $this->timestampRegion->get($this->timestampKey);
     $hash = $this->getHash($query, $criteria, null, null, null, $timestamp ? $timestamp->time : null);
     $rsm = $this->getResultSetMapping();
     $querykey = new QueryCacheKey($hash, 0, Cache::MODE_NORMAL);
     $queryCache = $this->cache->getQueryCache($this->regionName);
     $cacheResult = $queryCache->get($querykey, $rsm);
     if ($cacheResult !== null) {
         if ($this->cacheLogger) {
             $this->cacheLogger->queryCacheHit($this->regionName, $querykey);
         }
         return $cacheResult;
     }
     $result = $this->persister->loadCriteria($criteria);
     $cached = $queryCache->put($querykey, $rsm, $result);
     if ($this->cacheLogger) {
         if ($result) {
             $this->cacheLogger->queryCacheMiss($this->regionName, $querykey);
         }
         if ($cached) {
             $this->cacheLogger->queryCachePut($this->regionName, $querykey);
         }
     }
     return $result;
 }
 /**
  * Load from second level cache or executes the query and put into cache.
  *
  * @param ArrayCollection|array|null $parameters
  * @param integer|null               $hydrationMode
  *
  * @return mixed
  */
 private function executeUsingQueryCache($parameters = null, $hydrationMode = null)
 {
     $rsm = $this->getResultSetMapping();
     $querykey = new QueryCacheKey($this->getHash(), $this->lifetime, $this->cacheMode ?: Cache::MODE_NORMAL);
     $queryCache = $this->_em->getCache()->getQueryCache($this->cacheRegion);
     $result = $queryCache->get($querykey, $rsm, $this->_hints);
     if ($result !== null) {
         if ($this->cacheLogger) {
             $this->cacheLogger->queryCacheHit($queryCache->getRegion()->getName(), $querykey);
         }
         return $result;
     }
     $result = $this->executeIgnoreQueryCache($parameters, $hydrationMode);
     $cached = $queryCache->put($querykey, $rsm, $result, $this->_hints);
     if ($this->cacheLogger) {
         $this->cacheLogger->queryCacheMiss($queryCache->getRegion()->getName(), $querykey);
         if ($cached) {
             $this->cacheLogger->queryCachePut($queryCache->getRegion()->getName(), $querykey);
         }
     }
     return $result;
 }