默認情況下,輸出緩存是基於控制器的。因此,當你看到一個控制器的命名是否相同時,它將生成或使用相同的緩存(如果緩存目錄在兩個地方都是相同的)。
您最佳的解決方法是使用緩存驅動程序並手動存儲緩存。以下是控制器代碼示例:
public function index()
{
// If we have a cache just return it and be done.
if ($mobile = $this->cache->get('page_mobile') AND $this->agent->is_mobile())
{
$this->output->set_output($mobile);
return TRUE;
}
elseif ($page = $this->cache->get('page))
{
$this->output->set_output($page);
return TRUE;
}
$vars = array();
// Save a cache and output the page.
if ($this->template->is_mobile)
{
$home = $this->load->view('page_mobile', $vars, TRUE);
$this->cache->save('controller_mobile', $home, 500);
$this->output->set_output($home);
}
else
{
$home = $this->load->view('page', $vars, TRUE);
$this->cache->save('controller', $home, 500);
$this->output->set_output($home);
}
}
這是非常有用的,謝謝埃裏克! – Ben