2016-01-13 124 views
0

我有以下功能,但它沒有緩存。有什麼我失蹤?環境:Doctrine Common和DBAL,PHP,MySQL。我應該沒有緩存ID一個變量?緩存不工作

function getGeo($latitude, $longitude, $radius, $numResults, $volunteerPid, $startPosition, $pageSize) 
    { 
     $cacheDriver = new Doctrine\Common\Cache\ArrayCache(); 
     $geoQuery = $cacheDriver->fetch($volunteerPid); 
     if ($geoQuery === false) { 
      $geoQuery = $this->connection->prepare("call sproc_qryGeo($latitude, $longitude, $radius, $numResults, $volunteerPid, $startPosition, $pageSize)"); 
      $cacheDriver->save($volunteerPid, $geoQuery); 
      echo "NOT CACHED"; 
     } 
     return $geoQuery; 
    } 
+1

afaik'ArrayCache'就像一個flash消息,它只存儲在一個頁面上。頁面重新加載後,它消失了。這是你的情況嗎?你期望與頁面重新加載緩存? –

+0

好的。我嘗試過使用Result Cache,但是它錯誤地出現在'$ config-> setResultCacheImpl(new \ Doctrine \ Common \ Cache \ ApcCache());'即使ApcCache.php文件位於Doctrine \ Common \緩存文件夾。我得到錯誤'傳遞給Doctrine的參數\ DBAL \ Configuration :: setResultCacheImpl()必須是Doctrine \ DBAL \ Cache \ Cache的實例,Doctrine \ Common \ Cache \ ApcCache實例'任何想法爲什麼我會得到那個錯誤? – stormchaser

+0

請提出一個新問題。 –

回答

0

作爲來自cache types definintions on Doctrine siteArrayCache具有請求的壽命。所以,在你重新加載頁面之後 - 你的緩存是不見了

所以,如果這是你的情況 - 考慮另一個緩存存儲,Doctrine支持一堆。