如标题所言,确实是简单灵活。看来想要摆脱Codeigniter越来越难了。 看看怎样使用吧 首先,在config.php中设置一下缓存目录,这个目录要存在且可写入 $config[‘mp_cache_dir’] = ‘application/mp_cache/'; 好了,现在看看代码 /加载library,可以放在构造函数中/ $this->load->library(‘MP_Cache’); /抓取名为listNews的缓存/ $listNews = $this->mp_cache->get(‘listNews’); if($listNews===false){ //没有缓存数据,则查询数据库 $listNews = $this->News_model->getNewslist(‘guest’)->result(); //创建缓存,命名为listNews。在mp_cache目录下就生成了listNews.cache文件,内容是序列化的数据 $this->mp_cache->write($listNews, ‘listNews’); } $data[‘listNews’]= $listNews; $this->layout->view(‘news’, $data); 两个注意点: 1,缓存数据,必须是data,而不是resource id。如,在使用AR后用result(),result_array()等返回的数据 2,缓存名不要重复。可以使用子文件夹分隔。如,$listNews = $this->mp_cache->get(‘news/listNews’);同样创建缓存数据片段用$this->mp_cache->write($listNews, ‘news/listNews’);(php5下news文件夹会自动创建) 其他方法: $this->mp_cache->delete($filename) 删除名为$filename的cache.
最后修改于 2009-03-28