In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
How are phpcms v9 cache files generated? This problem may be often seen in our daily study or work. I hope you can gain a lot from this question. The following is the reference content that the editor brings to you, let's take a look at it!
How are phpcms v9 cache files generated?
This article introduces the cache structure of phpcms
I didn't do any in-depth study, but there is something remarkable about phpcms's idea, which is so convincing. Here we share an implementation scheme of phpcms cache.
/ include/cache.func.php
At first, some phpcms cache functions are defined. Phpcms cache is divided into table cache, model cache, model field cache, and module cache. First of all, these are based on table cache.
There was a function at the beginning.
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;}
This function calls a bunch of caching functions to generate the cached.
First, the first function cache_common
You can take a look at the note below, which writes the prefix name _ model, prefix name _ category, prefix name _ module, prefix name _ type, prefix name _ area, etc., to the corresponding table of the $CACHE array (for example, the data of the model table $CACHE ["model"] = $arr,$arr is the data of the phpcms_model table)
Function cache_common () {global $db;$data = array (); $result = $db- > query ("SELECT `module`, `name`, `path`, `url`, `iscore`, `version`FROM `" .DB _ PRE. "module`module`modulled` = 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;} $db- > free_result ($result); $CACHE [' MODULE'] = $data;// is written to $CACHE;$data = array (); $result = $db- > query ("SELECT * FROM `" .DB _ PRE. "model`WHERE `roomled` = 0") While ($r = $db- > fetch_array ($result)) {$data [$r ['modelid']] = $r;} $db- > free_result ($result); $CACHE [' MODEL'] = $data;$data = array (); / / the contents of the corresponding model table are written to the array $CACHE $result = $db- > query ("SELECT `catid`, `module`, `type`, `modelid`, `catname`, `style`, `image`, `catdir`, `url`, `parentid`, `arrparentid`, `pardirent`, `child`, `arrchildid`, `items`, `citems`, `pitems`, `ismenu`, `letter` FROM `" .DB _ PRE. "roomy`WHERE 1 ORDER BY `listorder`, `catid`"); while ($r = $db- > fetch_array ($result)) {r ['url'] = url ($r [' url']); $data [$r [catid'] = $; db- > free_result ($result); $CACHE [CATEGORY'] = $data / / write all the columns to the $CACHE array $data = array (); $result = $db- > query ("SELECT `typeid`, `modelid`, `module`, `name`, `style`, `typedir`, `url`FROM `" .DB _ PRE. "type`WHERE 1 ORDER BY `storlider`, `typeid`"); while ($r = $db- > fetch_array ($result)) {$data [$r ['typeid']] = $r;} $db- > free_result ($result); $CACHE [' TYPE'] = $data / / write the data in all category tables to $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;// all regional tables write $CACHE;$data = array () $result = $db- > query ("SELECT `urlruleid`, `urlrule` FROM `" .DB _ PRE. "urlrule` WHERE 1 ORDER BY `urlruleid`"); while ($r = $db- > fetch_array ($result)) {$data [$['urlruleid']] = $r [' urlrule'];} $db- > free_result ($result); $CACHE ['URLRULE'] = $data;// writes all url rules to the cache $data = array (); $r = $db- > get_one ("SELECT `setting`FROM`" .DB. $setting = $r ['setting']; eval ("\ $PHPCMS = $setting;"); if ($PHPCMS [' siteurl'] = =') $PHPCMS ['siteurl'] = SITE_URL;$CACHE [' PHPCMS'] = $PHPCMS;// finally calls the cache_write method to write all the arrays to the common.php location / date/cache/common.php changes cache_write ('common.php', $CACHE) according to the system variable Hui; return $CACHE;}
Phpcms table cache is mainly implemented by using a function called cache_table: $table is the table name to be cached, $fileds is the field name of the query, default is'*', where clause in $where sql statement, $order sorting, whether $isline turns on field cache is disabled by default, if table field cache and table cache are turned on, both table field cache and table cache will be enabled at the same time.
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 0title 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_merge ($r, $setting);} $key = $r [$keyfield]; $value = $valfield? $r [$valfield]: $r; $data [$key] = $value; if ($iscacheline) cache_write ($table.'_'.$key.'.php', $value); / / Table Field Cache} $db- > free_result ($result); cache_write ($table.'.php', $data) / / Table cache}
Write the data array to the corresponding cache file. The above function is to determine whether the constant CACHE_PATH has a path with the default data/cache, and then use file_put_contents to write the cached data to the corresponding cachefile.
Function cache_write ($file, $array, $path =') {if (! is_array ($array)) return false;$array = ""; $cachefile = ($path? $path: CACHE_PATH). $file;$strlen = file_put_contents ($cachefile, $array); @ chmod ($cachefile, 0777); return $strlen;}
As for others, you can refer to the above method to add, you can check the corresponding cache.func.php.
/ / caching model table function cache_model () {cache_table (DB_PRE.'model','*', 'modelid', 1);} / caching classification table generation file path is.. / data/cachecategory_catid.phpfunction cache_category () {cache_table (DB_PRE.'category',' *', 'listorder,catid', 1);}
Cache category table generation path
. / data/cache/type_typeid.phpfunction cache_type () {cache_table (DB_PRE.'type','*', 'listorder,typeid', 1);} / cache region list
Generation path:.. / data/cache/area_areaid.php
Function cache_area () {cache_table (DB_PRE.'area','*', 'listorder,areaid', 1);} / cache user group table / / generate path:.. / data/cache member_grounp_group_id.phpfunction cache_member_group () {cache_table (DB_PRE.'member_group',' *', 'groupid', 1) Cache_table (DB_PRE.'member_group','*', 'name',', 'groupid', 0);} / cache role table / / generation path:. / data/cache/role_roleid.phpfunction cache_role () {cache_table (DB_PRE.'role',' *', 'name',', 'listorder,roleid') } / / Cache author table / / generate path:. / data/cache/author_authorid.phpfunction cache_author () {cache_table (DB_PRE.'author','*', 'name',', 'listorder,authorid', 0,100);} function cache_keyword () {cache_table (DB_PRE.'keyword',' *', 'tag',', 'listorder,usetimes', 0,100) } function cache_copyfrom () {cache_table (DB_PRE.'copyfrom','*', 'listorder,usetimes', 0100);} function cache_pos () {cache_table (DB_PRE.'position',' *', 'name',', 'listorder,posid', 0);} Thank you for reading! After reading the above, do you have a general idea of how phpcms v9 cache files are generated? I hope the content of the article will be helpful to all of you. If you want to know more about the relevant articles, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.