我在CodeIgniter中遇到缓存问题。
然后我下载了CodeIgniter的缓存库并放入libraries文件夹,并将php代码放入控制器文件中:
<?php
class Cache extends CI_Controller
{
public function index()
{
$this->cache->set('test_cache', 'test_cache_content', 300); // 5 minutes
}
}
?>
此 test_cache 缓存文件不在缓存文件夹中。在config.php文件中,cache_path是默认值。
然后我想获取test_cache内容并将代码放入控制器:
<?php
class Cache extends CI_Controller
{
public function get()
{
$data = $this->cache->get('test_cache');
echo var_dump($data);
}
}
?>
然后我看到 null 。我在codeigniter中搜索缓存,但没有。
答案 0 :(得分:2)
只是为了确保,因为它实际上不在上面的代码中,你确实加载了一个缓存驱动程序,对吧:
// example from CodeIgniter Cache docs.
$this->load->driver('cache', array('adapter' => 'apc', 'backup' => 'file'));
因为如果你没有它默认为虚拟驱动程序。虚拟驱动程序没有任何保存,所以我认为你不需要它。