Discuz教程网

[插件制作] Discuz X3文件缓存的生成和读取教程

[复制链接]
authicon dly 发表于 2013-9-1 15:56:14 | 显示全部楼层 |阅读模式
生成缓存:

1.引入缓存函数:
require_once libfile('function/cache');

2.查询获得要缓存的数据

比如叫 $cachedata

  1. $query = DB::query("SELECT * FROM ".DB::table('zzbuluo_zs_hao123'). " where isagree = '-1' ORDER BY id DESC");
  2. $cachedata= array();
  3. while($value = DB::fetch($query)){
  4.                $cachedata[$value['id']] = $value;
  5. }
复制代码


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)

  1. <?php
  2. //Discuz! cache file, DO NOT modify me!
  3. //Identify: b4aa4efb303e29e25b340790f4d40586

  4. $website = array (
  5.   0 => '2',
  6.   1 => '3',
  7.   2 =>
  8.   array (
  9.     0 => 'abc',
  10.   ),
  11. );
  12. $abc = array (
  13.   0 => '2',
  14.   1 => '3',
  15.   2 =>
  16.   array (
  17.     0 => 'abc',
  18.   ),
  19. );
  20. ?>
复制代码

读取缓存:

游客,如果您要查看本帖隐藏内容请回复

用法:

  1. $cachefile = DISCUZ_ROOT.'data/sysdata/cache_ceshi.php';
  2. if(file_exists($cachefile)){
  3.           @require_once DISCUZ_ROOT.'data/sysdata/cache_ceshi.php';
  4. }else{
  5.      require_once libfile('function/cache');
  6.      $cachedata = array('2','3', array('abc'));
  7.      writetocache('ceshi', getcachevars(array('cachedata' => $cachedata)));
  8. }
  9. print_r($cachedata);
复制代码




上一篇:不能预览,总显示灯鹫控制台安全设置域名绑定
下一篇:1314学习网签到记录贴-2013年9月2日
authicon ═☆o鈊薠o☆ 发表于 2013-9-11 09:42:11 | 显示全部楼层
我瞧瞧....................
authicon csacx 发表于 2014-11-15 00:45:09 | 显示全部楼层
cache('ceshi', getcachevars(array('website' => $cachedata, 'abc' =
authicon 小小军022 发表于 2015-7-21 20:28:59 -----手机频道 | 显示全部楼层
Discuz X3文件缓存的生成和读取教程
authicon 网络无名 发表于 2016-3-6 00:15:09 | 显示全部楼层
嗯嗯嗯嗯嗯嗯嗯嗯嗯
authicon 网络无名 发表于 2016-3-6 00:15:36 | 显示全部楼层
看看~~~ee测试啊
authicon henri001 发表于 2016-3-10 20:00:09 | 显示全部楼层
正好需要看下这个,二次开发需要用到
authicon 哲男 发表于 2017-1-10 15:36:57 | 显示全部楼层
gooooooood
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

1314学习网 ( 浙ICP备10214163号 )

GMT+8, 2024-3-28 23:07

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表