菜单

【phpcms-v9】phpcms-v9的缓存结构

2019年7月7日 - 计算机教程

//将所有的url规则写入缓存

1、用途
$PHPCMS 是一个一维数组,主要用来保存网站配置信息。

$data = array();
$result = $db->query(“SELECT
`typeid`,`modelid`,`module`,`name`,`style`,`typedir`,`url`
FROM `”.DB_PRE.”type` WHERE 1 ORDER BY `listorder`,`typeid`”);
while($r = $db->fetch_array($result))
{
   $data[$r[‘typeid’]] = $r;
}
$db->free_result($result);
$CACHE[‘TYPE’] = $data;
//以上是将所有的 类别表里的数据写入$CACHE

 

$data = array();
$result = $db->query(“SELECT
`areaid`,`name`,`style`,`parentid`,`arrparentid`,`child`,`arrchildid`
FROM `”.DB_PRE.”area` WHERE 1 ORDER BY `listorder`,`areaid`”);
while($r = $db->fetch_array($result))
{
   $data[$r[‘areaid’]] = $r;
}
$db->free_result($result);
$CACHE[‘AREA’] = $data;

2、如何设置
您可以登录网站后台=>系统设置=>基本配置,然后在线修改参数值。您也可以通过修改
./admin/templates/setting.tpl.php
增加表单项目来增加数组元素。数组信息序列化(serialize)后被保存到
phpcms_module 表的 setting 字段里,同时还产生一个数组缓存保存到
./data/cache/common.php ,每次请求系统都默认加载该缓存文件。

这篇文章继续介绍phpcms的缓存结构
我并没有做深入的学习,但是phpcms的想法上却是有他的过人之处,太令人折服了,这里分享phpcms缓存的一中实现方案
/include/cache.func.php
这里最先主要是定义了一些phpcms的缓存函数,phpcms的缓存分为,表缓存,模型缓存,模型字段缓存,还有模块缓存,首先这些都是基于表的缓存的。
最开始有一个函数
function cache_all()
{
@set_time_limit(600);
cache_common();
cache_module();
cache_model();
cache_category();
cache_area();
cache_type();
cache_member_group();
    cache_role();
cache_author();
cache_keyword();
cache_copyfrom();
cache_pos();
    cache_status();
cache_workflow();
tags_update();
return TRUE;
}
这个函数就调用一大堆的缓存函数来生成缓存的。
首先第一个函数 cache_common
大家可以看下面的注释,是将 前缀名_model,前缀名_category ,前缀名_
module,前缀名,前缀名_type,前缀名_area,等等写入到$CACHE数组的对应下表之中
(比如model
表的数据$CACHE[“model”]=$arr,$arr为phpcms_model表的数据)
function cache_common()
{
global $db;
$data = array();
$result = $db->query(“SELECT
`module`,`name`,`path`,`url`,`iscore`,`version` FROM
`”.DB_PRE.”module` WHERE `disabled`=0″);
while($r = $db->fetch_array($result))
{
   if(!$r[‘path’]) $r[‘path’] = $r[‘module’] == ‘phpcms’ ? ” :
$r[‘module’].’/’;
   if(!$r[‘url’]) $r[‘url’] = $r[‘module’] == ‘phpcms’ ? ” :
$r[‘module’].’/’;
   $data[$r[‘module’]] = $r;
}


//最后调用cache_write方法将所有的数组写入common.php
位置/date/cache/common.php根据系统变量慧有所改动

4、数组元素 $PHPCMS[sitename] = ‘phpcms网站管理系统’;
$PHPCMS[siteurl] = ‘http://localhost/2007/phpcms/‘;
$PHPCMS[logo] = ‘images/logo.gif’;
$PHPCMS[linklogo] = ‘images/linklogo.gif’;
$PHPCMS[icpno] = ‘陕ICP备***号’;
$PHPCMS[bazscert] = ‘cert/bazs.cert’;
$PHPCMS[seo_title] = ‘phpcms网站管理系统’;
$PHPCMS[seo_keywords] = ‘phpcms网站管理系统’;
$PHPCMS[seo_description] = ‘phpcms网站管理系统’;
$PHPCMS[ishtml] = ‘1’;
$PHPCMS[index] = ‘index’;
$PHPCMS[fileext] = ‘html’;
$PHPCMS[webmasteremail] = ‘master@domain.com’;
$PHPCMS[copyright] = ‘phpcms网站管理系统’;
$PHPCMS[enableeditor] = ‘1’;
$PHPCMS[province] = ‘陕西省’;
$PHPCMS[city] = ‘西安市’;
$PHPCMS[area] = ‘莲湖区’;
$PHPCMS[uploaddir] = ‘uploadfile’;
$PHPCMS[uploadfiletype] =
‘gif|jpg|jpeg|png|bmp|txt|zip|rar|doc|swf’;
$PHPCMS[uploadfunctype] = ‘1’;
$PHPCMS[enablegzip] = ‘0’;
$PHPCMS[maxpage] = ‘100’;
$PHPCMS[pagesize] = ’20’;
$PHPCMS[autoupdatepagenum] = ‘5’;
$PHPCMS[searchtime] = ’10’;
$PHPCMS[maxsearchresults] = ‘500’;
$PHPCMS[searchperpage] = ’10’;
$PHPCMS[searchcontent] = ‘1’;
$PHPCMS[authkey] = ‘www.phpcms.cn’;
$PHPCMS[adminaccessip] = ”;
$PHPCMS[maxfailedtimes] = ‘5’;
$PHPCMS[maxlockedtime] = ‘1’;
$PHPCMS[enablebanip] = ‘0’;
$PHPCMS[enableadmincheckcode] = ‘0’;
$PHPCMS[enablethumb] = ‘1’;
$PHPCMS[thumb_width] = ‘150’;
$PHPCMS[thumb_height] = ‘150’;
$PHPCMS[water_type] = ‘2’;
$PHPCMS[water_text] = ‘www.phpcms.cn’;
$PHPCMS[water_font] = ‘include/fonts/simhei.ttf’;
$PHPCMS[water_fontsize] = ’18’;
$PHPCMS[water_fontcolor] = ‘#ff0000’;
$PHPCMS[water_image] = ‘images/watermark.gif’;
$PHPCMS[water_pos] = ‘9’;
$PHPCMS[sendmailtype] = ‘smtp’;
$PHPCMS[smtphost] = ‘smtp.163.com’;
$PHPCMS[smtpuser] = ‘xxxxx@163.com’;
$PHPCMS[smtppass] = ‘********’;
$PHPCMS[smtpport] = ’25’;
$PHPCMS[enablesignature] = ‘1’;
$PHPCMS[signature] = ‘ E-mail 签名‘; $PHPCMS[enableftp] = ‘0’;
$PHPCMS[ftphost] = ”;
$PHPCMS[ftpport] = ’21’;
$PHPCMS[ftpuser] = ”;
$PHPCMS[ftppass] = ”;
$PHPCMS[ftpwebpath] = ”;
$PHPCMS[enablepassport] = ‘0’;
$PHPCMS[passport_file] = ‘discuz’;
$PHPCMS[passport_charset] = ‘gbk’;
$PHPCMS[passport_url] = ‘http://bbs.phpcms.cn/api/passport.php‘;
$PHPCMS[passport_key] = ‘xxxxxxxxxxyyyyyyy’;
$PHPCMS[enableserverpassport] = ‘0’;
$PHPCMS[passport_serverurl] = ”;
$PHPCMS[passport_registerurl] = ”;
$PHPCMS[passport_loginurl] = ”;
$PHPCMS[passport_logouturl] = ”;
$PHPCMS[passport_getpasswordurl] = ”;
$PHPCMS[passport_serverkey] = ”;
$PHPCMS[passport_expire] = ”;
$PHPCMS[enabletm] = ‘0’;
$PHPCMS[qq] = ”;
$PHPCMS[msn] = ”;
$PHPCMS[skype] = ”;
$PHPCMS[taobao] = ”;
$PHPCMS[alibaba] = ”;
$PHPCMS[enable53kf] = ‘0’;
$PHPCMS[kf_arg] = ”;
$PHPCMS[kf_style] = ”;
$PHPCMS[version] = ‘2007’

//以上是对应的 model表里的内容写入数组$CACHE;

3、作用范围 $PHPCMS
数组是系统默认加载的,可以在整个项目的任何php文件和模板中调用。

cache_write(‘common.php’, $CACHE);
    
return $CACHE;
}
phpcms表缓存的实现方式主要是:利用一个叫cache_table函数$table是要缓存的表名,$fileds
是查询的字段名字,默认为 ‘ * ‘,$where sql语句中的where 子句,$order
排序,
$isline是否开启字段缓存默认为不开启,如果开启表字段缓存和表缓存将同时进行
function cache_table($table, $fields = ‘*’, $valfield = ”, $where =
”, $order = ”, $iscacheline = 0, $number = 0)
{
global $db;
$keyfield = $db->get_primary($table);
$data = array();
if($where) $where = ” WHERE $where”;
if(!$order) $order = $keyfield;
$limit = $number ? “LIMIT 0,$number” : ”;
$result = $db->query(“SELECT $fields FROM `$table` $where ORDER BY
$order $limit”);
$table = preg_replace(“/^”.DB_PRE.”(.*)$/”, “”, $table);
while($r = $db->fetch_array($result))
{
   if(isset($r[‘setting’]) && !empty($r[‘setting’]))
   {
    $setting = $r[‘setting’];
    eval(“\$setting = $setting;”);
    unset($r[‘setting’]);
    if(is_array($setting)) $r = array_402.com,merge($r, $setting);
        }
   $key = $r[$keyfield];
   $value = $valfield ? $r[$valfield] : $r;
   $data[$key] = $value;
   if($iscacheline) cache_write($table.’_’.$key.’.php’, $value);
//表字段缓存
}
$db->free_result($result);
cache_write($table.’.php’, $data) ;// 表缓存


$data = array();
$result = $db->query(“SELECT * FROM `”.DB_PRE.”model` WHERE
`disabled`=0″);
while($r = $db->fetch_array($result))
{
   $data[$r[‘modelid’]] = $r;
}
$db->free_result($result);
$CACHE[‘MODEL’] = $data;
$data = array();

相关文章

发表评论

电子邮件地址不会被公开。 必填项已用*标注

网站地图xml地图