0
在我的一個模型中,我使用文件緩存記憶預處理數據以加快列表視圖。CakePHP 2.4:更新緩存失敗,插入但未更新
在我的回調afterSave()我調用應該強制更新或創建緩存項的方法,但由於某些原因,它只適用於更新,但不適用於創建。
下面是代碼:
public function afterSave($created, $options = array())
{
exec('sudo /root/tools/sync-home-wap-GKM.sh');
$content = $this->findById($this->id);
$this->enhanceContent($content, true);
}
的重要電話是enhanceContent($內容,真)產生的附加數據或從緩存中獲取它。真正初始化強制更新緩存(至少我希望如此)。
private function enhanceContent($content, $bForce = false)
{
if (!isset($content['Content']['id']))
throw new NotFoundException(__('Invalid Content Array: '.$content));
if ($bForce)
Cache::delete('ContentPretty'.$content['Content']['id'], 'long');
$contentpretty = Cache::read('ContentPretty'.$content['Content']['id'], 'long');
if ($contentpretty === false) {
$content['Content']['preview'] = $this->getImageName(
(int)$content['Content']['objnbr'], 'small', false
);
.... Do a lot of other things not important
Cache::write('ContentPretty'.$content['Content']['id'], $content['Content'], 'long');
} else {
$content['Content'] = $contentpretty;
}
//debug($content);
return $content;
}
大家有一個想法,爲什麼在列表中的數據是不存在添加新內容之後,但編輯相同的內容,並重新保存後會出現?
感謝您的任何提示!
災難珍妮
有些情況下,afterSave將不會被調用。所以我會在創建新內容後確認這實際上是被調用的。 – Kai
我在測試環境的afterSave方法中插入了退出語句,並在添加新內容時停止執行。所以我猜這個方法確實叫做。 –