1

Hi i want to cache the result of query. I have already:

    $now = time();
    $lastMonth = 30*24*3600;

    $period = $now-$lastMonth;

    $qb=$this->_em->createQueryBuilder()
             ->select('s') 
             ->addSelect('u') 
             ->addSelect('COUNT(s.id) AS suggestedCount')
             ->from('WallBundle:Status', 's') 
             ->innerJoin('s.user', 'u') 
             ->where('s.time >= :period')
             ->andWhere('s.suggested_status = true')
             ->groupBy('s.user')
             ->setParameter('period', $period)
             ->orderBy('suggestedCount', 'DESC')
             ->setMaxResults(10)
             ; 

    $query=$qb->getQuery();  
    $query->useResultCache(true,30800,'elite10');
    $query->useQueryCache(true);

    return $query->getResult();

But it still does not cache. When i remove the

"->where('s.time >= :period')"

and

->setParameter('period', $period)

It works... so.. where is the problem?

4

1 回答 1

1

您正在使用查询缓存$query->useQueryCache(true);$period = $now-$lastMonth;因此没有两个查询是相同的并且不能被缓存。如果您需要低于它,请将参数四舍五入到 x 小时。

于 2013-08-31T15:58:35.977 回答