我想在CodeIgniter中缓存一个查询。我在测试中做了一个控制器,我命名为show.php
:
class Show extends CI_Controller{
public function __construct()
{
parent::__construct();
$this->load->model('rejaal_show');
}
public function _remap($method = '',$param = array())
{
$method = intval($method);
$this->output->cache(5);
var_dump ($this->rejaal_show->temp($method));
}
}
字符串
我给这个模型命名为rejaal_show.php
:
public function temp($id)
{
$this->db->cache_on();
$this->db->where('id',$id);
$query = $this->db->get('system_store_table');
return $query->result();
}
型
当我第一次调用http://localhost/rejaal/show/1
时,它会显示一个结果,但当我第二次调用它时,它不会显示任何东西。
我应该删除查询缓存文件以重新显示它吗?我应该如何解决这个问题?
特别感谢您的关注。
2条答案
按热度按时间31moq8wy1#
你能确认你已经把
$db['default']['cachedir']
设置为application/config/database.php
中一个可写文件夹的路径,并且当第一次运行查询时,它会在那里创建一个缓存文件吗?我能想到的另一个失败的原因是你使用了
_remap
覆盖。我没有使用_remap
使用数据库缓存,但知道CodeIgniter在你的缓存文件夹中创建了一个名为controller+action的文件夹,如果使用remap,可能处理得不好?如果我错了,有人纠正我。cgh8pdjw2#
在Web Page Caching的CodeIgniter用户指南页面中,它说:
在视图中执行
var_dump
。