VPS参考测评推荐
专注分享VPS主机优惠信息
衡天云优惠活动
华纳云最新优惠促销活动
jtti最新优惠促销活动

如何生成phpcms v9缓存文件

locvps
主机参考:VPS测评参考推荐/专注分享VPS服务器优惠信息!若您是商家可以在本站进行投稿,查看详情!此外我们还提供软文收录、PayPal代付、广告赞助等服务,查看详情!
我们发布的部分优惠活动文章可能存在时效性,购买时建议在本站搜索商家名称可查看相关文章充分了解该商家!若非中文页面可使用Edge浏览器同步翻译!PayPal代付/收录合作

如何生成phpcms v9缓存文件

phpcms v9缓存文件是如何生成的?

本文介绍了phpcms的缓存结构。

我没有做深入的研究,但phpcms的想法有其自身的优势,这是如此令人信服。在这里,我分享一个phpcms缓存的二合一实现方案。

/include/cache.func.php

首先,定义了phpcms的一些缓存函数。phpcms的缓存分为表缓存、模型缓存、模型字段缓存和模块缓存。首先,这些是基于表的缓存。

开头有一个函数。

函数cache _ all(){ @ set _ time _ limit(600);cache _ common();缓存模块();cache _ model();cache _ category();cache _ area();cache _ type();缓存成员组();cache _ role();cache _ author();cache _ keyword();cache _ copy from();cache _ pos();cache _ status();cache _ workflow();tags _ update();返回TRUE这个函数调用很多缓存函数来生成缓存。

首先是第一个函数,cache_common。

可以看到以下注释:写前缀名_型号、前缀名_类别、前缀名_模块、前缀名、前缀名_类型、前缀名_区域等。放入$CACHE数组的对应表中(例如,模型表$ CACHE【“model“】= $ arr的数据,$ arr是phpcms_model表的数据)。

函数cache _ common(){ global $ db;$ data = array();$ result = $ d B- & gt;查询(& quot从“中选择“模块”、“名称”、“路径”、“url”、“iscore”、“版本”。DB_PRE。"模块`其中` disabled `= 0 & quot;);while($ r = $ db-& gt;fetch _ array($ result)){ if(!$ r【& amp;#39;路径与方法。#39;】)$ r【& amp;#39;路径与方法。#39;】= $ r【& amp;#39;模块与应用。#39;】= = = & amp;#39;phpcms & amp#39;?& amp#39;& amp#39;:$ r【& amp;#39;模块与应用。#39;].& amp#39;/& amp;#39;;如果(!$ r【& amp;#39;url & amp#39;】)$ r【& amp;#39;url & amp#39;】= $ r【& amp;#39;模块与应用。#39;】= = = & amp;#39;phpcms & amp#39;?& amp#39;& amp#39;:$ r【& amp;#39;模块与应用。#39;].& amp#39;/& amp;#39;;$ data【$ r 【& amp;#39;模块与应用。#39;】】= $ r;} $ d B- & gt;free _ result($ result);$ CACHE【& amp;#39;模块与应用。#39;】= $ data//以上是将对应的模块写入$ CACHE$ data = array();$ result = $ d B- & gt;查询(& quotSELECT * FROM ` & quot。DB_PRE。"模型`其中` disabled `= 0 & quot;);while($ r = $ db-& gt;fetch _ array($ result)){ $ data【$ r【& amp;#39;modelid & amp#39;】】= $ r;} $ d B- & gt;free _ result($ result);$ CACHE【& amp;#39;模特与模特。#39;】= $ data$ data = array();//以上是写入数组$CACHE的对应模型表中的内容;$ result = $ d B- & gt;查询(& quot请选择“catid”、“module”、“type”、“modelid”、“catname”、“style”、“image”、“catdir”、“url”、“parentid”、“arrparentid”、“parentid”、“child”、“arrchildid”、“items”、“citems”、“pitems”、“ismenu”、“letter”FROM。DB_PRE。"类别“其中1个订单按listorder,catid` & quot);while($ r = $ db-& gt;fetch _ array($ result))。#39;url & amp#39;】= URL($ r【& amp;#39;url & amp#39;]);$ data【$ r 【& amp;#39;catid & amp#39;】】= $ r;} $ d B- & gt;free _ result($ result);$ CACHE【& amp;#39;类别与主题。#39;】= $ data//以上是将所有列写入$ CACHE array $ data = array();$ result = $ d B- & gt;查询(& quot从` & quot中选择` typeid `、` modelid `、` module `、` name `、` style `、` typedir `、` url `。DB_PRE。"键入“其中1 ORDER BY‘list ORDER‘,typeid` & quot);while($ r = $ db-& gt;fetch _ array($ result)){ $ data【$ r【& amp;#39;typeid & amp#39;】】= $ r;} $ d B- & gt;free _ result($ result);$ CACHE【& amp;#39;类型&amp。#39;】= $ data//以上是将类别表中的所有数据写入$ CACHE $ data = array();$ result = $ d B- & gt;查询(& quot从` & quot中选择` areaid `、` name `、` style `、` parentid `、` arrparentid `、` child `、` arrchildid `。DB_PRE。"area `其中1 ORDER BY `listorder,` areaid` & quot);while($ r = $ db-& gt;fetch _ array($ result)){ $ data【$ r【& amp;#39;areaid & amp#39;】】= $ r;} $ d B- & gt;free _ result($ result);$ CACHE【& amp;#39;面积和面积。#39;】= $ data//所有区域表都写入$ CACHE$ data = array();$ result = $ d B- & gt;查询(& quot从“urlruleid”中选择“urlrule”。DB_PRE。"urlrule `其中1 ORDER BY ` urlruleid `& quot;);while($ r = $ db-& gt;fetch _ array($ result)){ $ data【$ r【& amp;#39;urlruleid & amp#39;】】= $ r【& amp;#39;urlrule & amp#39;];} $ d B- & gt;free _ result($ result);$ CACHE【& amp;#39;URLRULE & amp#39;】= $ data//将所有url规则写入缓存$ data = array();$ r = $ d B- & gt;get _ one(& quot;从“设置”中选择“设置”。DB_PRE。"module` WHERE `module` = & amp#39;phpcms & amp#39;");$ setting = $ r【& amp;#39;设置&amp。#39;];eval(& quot;\ $ PHPCMS = $ setting");if($ PHPCMS【& amp;#39;网站链接& amp#39;】= = = & amp;#39;& amp#39;)$ PHPCMS【& amp;#39;网站链接& amp#39;】= SITE _ URL$ CACHE【& amp;#39;PHPCMS & amp#39;】= $ PHPCMS//最后,调用cache_write方法将所有数组写入common.php location/date/date/Cache/common . PHP Cache _ write(&;#39;common.php & amp#39;,$ CACHE);返回$ CACHE}phpcms表缓存主要通过使用一个名为cache_table的函数来实现,其中$table是要缓存的表的名称,$ files是查询的字段名称,默认为‘*‘,$ WHERESQL语句中的where子句,$order排序,$isline是否打开字段缓存默认情况下不打开,如果打开表字段缓存和表缓存,将同时进行。

函数cache _ table($ table,$ fields = & amp#39;* & amp#39;,$ valfield = & amp#39;& amp#39;,$ where = & amp#39;& amp#39;,$ order = & amp#39;& amp#39;,$iscacheline = 0,$ number = 0){ global $ db;$ key field = $ d B- & gt;get _ primary($ table);$ data = array();if($ where)$ where = & quot;WHERE $ where & quot;如果(!$ order)$ order = $ key field;$limit = $number?"限制0,$ number & quot:& amp#39;& amp#39;;$ result = $ d B- & gt;查询(& quot从`$ table `$ where ORDER BY $ ORDER $ limit & quot;中选择$fields);$ table = preg _ replace(& quot;/^"。DB_PRE。"(.*)$/& quot;,& quot",$ table);while($ r = $ db-& gt;fetch _ array($ result)){ if(isset($ r【& amp;#39;设置&amp。#39;】)& amp& amp!空的(r 【& amp;#39;设置&amp。#39;】)){ $ setting = $ r【& amp;#39;设置&amp。#39;];eval(& quot;\ $ setting = $ setting");unset(r 【& amp;#39;设置&amp。#39;]);if(is _ array(setting))$ r = array _ merge(r,$ setting);} $ key = $ r【$ key field】;$value = $valfield?$ r【$ valfield】:$ r;$ data【$ key】= $ value;if($ iscache line)cache _ write($ table。& amp#39;_ & amp#39;。$key。& amp#39;。php与#39;,$ value);//表字段缓存} $ db-& gt;free _ result($ result);cache _ write($ table。& amp#39;。php与#39;,$ data);//表缓存}将数据数组写入对应的缓存文件。上面的函数是判断常量CACHE_PATH是否有默认为data/cache的路径,然后用file_put_contents将缓存的数据写入对应的cachefile。

函数cache _ write($ file,$array,$ path = & amp#39;& amp#39;){if(!is _ array($ array))返回false$ array = & quot& lt?php \返回& quot。var _ export($ array,true)。";\n?& gt";$ cache file =($ path?$path : CACHE_PATH)。$ file$ strlen = file _ put _ contents($ cache file,$ array);@ chmod($ cache file,0777);return $ strlen}至于其他的,可以参考上面的方法添加。你可以查看相应的cache.func.php。

//缓存模型表函数cache _ model(){ cache _ table(db _ pre。&;#39;模特与模特。#39;,& amp#39;* & amp#39;,& amp#39;& amp#39;,& amp#39;& amp#39;,& amp#39;modelid & amp#39;, 1);}//缓存分类表生成的文件路径为../data/cache category _ catid . PHP function cache _ category(){ cache _ table(db _ pre。&;#39;类别与主题。#39;,& amp#39;* & amp#39;,& amp#39;& amp#39;,& amp#39;& amp#39;,& amp#39;列表顺序,catid & amp#39;, 1);}缓存类别表生成路径

../data/cache/type _ typeid . PHP function cache _ type(){ cache _ table(DB _ PRE。& amp#39;类型&amp。#39;,& amp#39;* & amp#39;,& amp#39;& amp#39;,& amp#39;& amp#39;,& amp#39;listorder,typeid & amp#39;, 1);}//缓存区列表生成路径:../数据/缓存/areaid.php地区。

函数cache _ area(){ cache _ table(DB _ PRE。& amp#39;面积和面积。#39;,& amp#39;* & amp#39;,& amp#39;& amp#39;,& amp#39;& amp#39;,& amp#39;listorder,areaid & amp#39;, 1);}//缓存用户组表//生成路径:。/data/cache member _ group NP _ group _ id . PHP function cache _ member _ group(){ cache _ table(db _ pre。&;#39;会员_团体&amp。#39;,& amp#39;* & amp#39;,& amp#39;& amp#39;,& amp#39;& amp#39;,& amp#39;groupid & amp#39;, 1);缓存表(DB_PRE。& amp#39;会员_团体&amp。#39;,& amp#39;* & amp#39;,& amp#39;姓名和名称。#39;,& amp#39;& amp#39;,& amp#39;groupid & amp#39;, 0);}//缓存角色表//生成路径:。/data/cache/role _ roleid . PHP function cache _ role(){ cache _ table(db _ pre。&;#39;角色与角色。#39;,& amp#39;* & amp#39;,& amp#39;姓名和名称。#39;,& amp#39;& amp#39;,& amp#39;listorder,roleid & amp#39;);}//缓存作者表//生成路径:。/data/cache/author _ authorized . PHP function cache _ author(){ cache _ table(db _ pre。&;#39;作者& amp#39;,& amp#39;* & amp#39;,& amp#39;姓名和名称。#39;,& amp#39;& amp#39;,& amp#39;listorder、authorid & amp#39;, 0, 100);} function cache _ keyword(){ cache _ table(DB _ PRE。& amp#39;关键词& amp#39;,& amp#39;* & amp#39;,& amp#39;标签& amp#39;,& amp#39;& amp#39;,& amp#39;列表顺序,使用时间和。#39;, 0, 100);}函数cache _ copy from(){ cache _ table(DB _ PRE。& amp#39;copyfrom & amp#39;,& amp#39;* & amp#39;,& amp#39;& amp#39;,& amp#39;& amp#39;,& amp#39;列表顺序,使用时间和。#39;, 0, 100);}函数cache _ pos(){ cache _ table(DB _ PRE。& amp#39;职位和职位。#39;,& amp#39;* & amp#39;,& amp#39;姓名和名称。#39;,& amp#39;& amp#39;,& amp#39;listorder、posid & amp#39;, 0);}PHP中文网站,很多免费的PHPCMS教程,欢迎在线学习!

这几篇文章你可能也喜欢:

本文由主机参考刊发,转载请注明:如何生成phpcms v9缓存文件 https://zhujicankao.com/115676.html

【腾讯云】领8888元采购礼包,抢爆款云服务器 每月 9元起,个人开发者加享折上折!
打赏
转载请注明原文链接:主机参考 » 如何生成phpcms v9缓存文件
主机参考仅做资料收集,不对商家任何信息及交易做信用担保,购买前请注意风险,有交易纠纷请自行解决!请查阅:特别声明

评论 抢沙发

评论前必须登录!