Codeigniter-带有子域的页面缓存
我正在使用默认的Codeigniter页面缓存,例如:Codeigniter-带有子域的页面缓存,codeigniter,caching,Codeigniter,Caching,我正在使用默认的Codeigniter页面缓存,例如: $this->output->cache(n); 我的问题是,我在两个不同的控制器中使用此功能,并获得一个重复的缓存页面,即为这两个控制器返回相同的页面。我认为这是由于使用了子域,例如: mobile.mysite.com=>Controller 1 mysite.com=>Controller 2 当我在两者上启用缓存时,返回的页面相同 如何为每个缓存生成不同的缓存 尊敬的Ben。默认情况下,输出缓存基于控制器。因此,正如您
$this->output->cache(n);
我的问题是,我在两个不同的控制器中使用此功能,并获得一个重复的缓存页面,即为这两个控制器返回相同的页面。我认为这是由于使用了子域,例如:
mobile.mysite.com=>Controller 1
mysite.com=>Controller 2
当我在两者上启用缓存时,返回的页面相同
如何为每个缓存生成不同的缓存
尊敬的Ben。默认情况下,输出缓存基于控制器。因此,正如您所看到的,如果控制器的名称相同,那么它将生成或使用相同的缓存(如果缓存目录在两个位置都相同) 最好的解决方法是使用缓存驱动程序并手动存储缓存。以下是控制器代码的示例:
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);
}
}