2011-11-12 55 views
0

我使用的是默認的笨頁面緩存例如:笨 - 頁面緩存使用子

$this->output->cache(n); 

我的問題是,我用這兩種不同的控制器內,並得到一個重複的緩存頁面即返回同一頁面對彼此而言。相信這是由於使用子域例如:

mobile.mysite.com =>控制器1

mysite.com =>控制器2

當我使雙方的高速緩存,我得到相同的頁面返回。

如何爲每個緩存生成不同的緩存?

問候,本。

回答

0

默認情況下,輸出緩存是基於控制器的。因此,當你看到一個控制器的命名是否相同時,它將生成或使用相同的緩存(如果緩存目錄在兩個地方都是相同的)。

您最佳的解決方法是使用緩存驅動程序並手動存儲緩存。以下是控制器代碼示例:

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); 
    } 
} 
+0

這是非常有用的,謝謝埃裏克! – Ben