2014-06-20 63 views
0

我:內存緩存不存儲對象屬性

//$this->MC->flush(); 
    $branchesWCounts = array(); 
    if (!$branchesWCounts = $this->MC->get('BRANCH_JOB_COUNT')) { 
     foreach ($branches as $branch) { 
      $branch->lt30min = $this->jobsAgeLessThan(1800, $branch->id); 
      $branch->gt30min = $this->jobs30to120($branch->id); 
      $branch->gt2hour = $this->jobs120Plus($branch->id); 
      $branch->problems = $this->problemJobCount($branch->id); 
      $branchesWCounts[] = $branch; 
     } 
     $this->MC->set('BRANCH_JOB_COUNT', $branchesWCounts); 
    } 

當緩存是不存在的事情就是這樣「lt30min」我的頁面上正確輸出其中一期工程。

但是,一旦緩存,它似乎無法檢索,似乎根本不存在於緩存中。

誰能告訴我爲什麼會發生這種情況?

回答

0

Memcache不會存儲PHP數組。您需要將其存儲爲字符串。使用serialize()

$this->MC->set('BRANCH_JOB_COUNT', serialize($branchesWCounts)); 

當從Memcache中得到它,你這時應該unserialize()