Discuz的插件机制给开发者一个好的开发环境,很多类库与函数数让你调用,你只用关注业务代码与模板。而有的操作是一定要知道的。如缓存机制。缓存是个好东西,当开发的功能需要大量的在数据库里读取时,而且数据库查询语句很复杂时,如果用户刷新一次页面就读取一次,那么服务器是受不了的。所以缓存文件是一定要的。 下面说一下如何操作缓存文件: 1、写入操作 $contents[]="你要写入的数据"; $cacheArray .= "\$contents=".arrayeval($contents).";\n"; writetocache('it618_contents', $cacheArray); 2、读取操作 include_once DISCUZ_ROOT.'./data/sysdata/cache_it618_contents'.php'; $strall=$contents[0]; 3、根据缓存时间判断操作 $cache_file = DISCUZ_ROOT.'./data/sysdata/cache_it618_contents.php'; if(($_G['timestamp'] - @filemtime($cache_file)) > $it618['cachetime']*60) { //你可以写缓存文件了 }else{ //你可以从缓存文件里读了 } |