生成缓存:
1.引入缓存函数:
require_once libfile('function/cache');
2.查询获得要缓存的数据
比如叫 $cachedata
- $query = DB::query("SELECT * FROM ".DB::table('zzbuluo_zs_hao123'). " where isagree = '-1' ORDER BY id DESC");
- $cachedata= array();
- while($value = DB::fetch($query)){
- $cachedata[$value['id']] = $value;
- }
复制代码
3.调用函数写入缓存:
令 $cachedata = array('2','3', array('abc'));
writetocache('ceshi', getcachevars(array('website' => $cachedata, 'abc' => $cachedata)));
缓存的结果是:
data/sysdata/cache_ceshi.php (X2缓存目录为data/cache,X2.5改为了data/sysdata)
- <?php
- //Discuz! cache file, DO NOT modify me!
- //Identify: b4aa4efb303e29e25b340790f4d40586
- $website = array (
- 0 => '2',
- 1 => '3',
- 2 =>
- array (
- 0 => 'abc',
- ),
- );
- $abc = array (
- 0 => '2',
- 1 => '3',
- 2 =>
- array (
- 0 => 'abc',
- ),
- );
- ?>
复制代码
读取缓存:
用法:
- $cachefile = DISCUZ_ROOT.'data/sysdata/cache_ceshi.php';
- if(file_exists($cachefile)){
- @require_once DISCUZ_ROOT.'data/sysdata/cache_ceshi.php';
- }else{
- require_once libfile('function/cache');
- $cachedata = array('2','3', array('abc'));
- writetocache('ceshi', getcachevars(array('cachedata' => $cachedata)));
- }
- print_r($cachedata);
复制代码
|
上一篇: 不能预览,总显示灯鹫控制台安全设置域名绑定下一篇: 1314学习网签到记录贴-2013年9月2日
|