亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

Home CMS Tutorial PHPCMS How are phpcms v9 cache files generated?

How are phpcms v9 cache files generated?

Jan 14, 2020 am 09:53 AM
phpcms

How are phpcms v9 cache files generated?

phpcms v9緩存文件是怎樣生成的?

這篇文章介紹phpcms的緩存結(jié)構(gòu)

我并沒有做深入的學(xué)習,但是phpcms的想法上卻是有他的過人之處,太令人折服了,這里分享phpcms緩存的一中實現(xiàn)方案

/include/cache.func.php

這里最先主要是定義了一些phpcms的緩存函數(shù),phpcms的緩存分為,表緩存,模型緩存,模型字段緩存,還有模塊緩存,首先這些都是基于表的緩存的。

最開始有一個函數(shù)

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;
}

這個函數(shù)就調(diào)用一大堆的緩存函數(shù)來生成緩存的。

首先第一個函數(shù) cache_common

大家可以看下面的注釋,是將 前綴名_model,前綴名_category ,前綴名_ module,前綴名,前綴名_type,前綴名_area,等等寫入到$CACHE數(shù)組的對應(yīng)下表之中 (比如model 表的數(shù)據(jù)$CACHE["model"]=$arr,$arr為phpcms_model表的數(shù)據(jù))

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;
}
$db->free_result($result);
$CACHE['MODULE'] = $data;
//以上是將對應(yīng)的模塊寫入$CACHE;
$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();
//以上是對應(yīng)的 model表里的內(nèi)容寫入數(shù)組$CACHE;
$result = $db->query("SELECT `catid`,`module`,`type`,`modelid`,`catname`,`style`,`image`,`catdir`,`url`,`parentid`,`arrparentid`,`parentdir`,`child`,`arrchildid`,`items`,`citems`,`pitems`,`ismenu`,`letter` FROM `".DB_PRE."category` WHERE 1 ORDER BY `listorder`,`catid`");
while($r = $db->fetch_array($result))
{
   $r['url'] = url($r['url']);
   $data[$r['catid']] = $r;
}
$db->free_result($result);
$CACHE['CATEGORY'] = $data;
//以上是將所有的欄目寫入$CACHE數(shù)組
$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;
//以上是將所有的 類別表里的數(shù)據(jù)寫入$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;
//所有的地區(qū)表寫入$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[$r['urlruleid']] = $r['urlrule'];
}
$db->free_result($result);
$CACHE['URLRULE'] = $data;
//將所有的url規(guī)則寫入緩存
$data = array();
    $r = $db->get_one("SELECT `setting` FROM `".DB_PRE."module` WHERE `module`='phpcms'");
$setting = $r['setting'];
eval("\$PHPCMS = $setting;");
if($PHPCMS['siteurl'] =='') $PHPCMS['siteurl'] = SITE_URL;
$CACHE['PHPCMS'] = $PHPCMS;
//最后調(diào)用cache_write方法將所有的數(shù)組寫入common.php 位置/date/cache/common.php根據(jù)系統(tǒng)變量慧有所改動
cache_write('common.php', $CACHE);
    
return $CACHE;
}

phpcms表緩存的實現(xiàn)方式主要是:利用一個叫cache_table函數(shù)$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_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) ;// 表緩存
}

將數(shù)據(jù)數(shù)組寫入對應(yīng)的緩存文件,以上這個函數(shù)就是判斷下常量CACHE_PATH是否存在默認是data/cache的路徑然后用file_put_contents 將緩存的數(shù)據(jù)寫入到對應(yīng)的cachefile中

function cache_write($file, $array, $path = '')
{
if(!is_array($array)) return false;
$array = "<?php\nreturn ".var_export($array, true).";\n?>";
$cachefile = ($path ? $path : CACHE_PATH).$file;
$strlen = file_put_contents($cachefile, $array);
@chmod($cachefile, 0777);
return $strlen;
}

至于其他的可以參照以上的方法進行添加,大家可以查查看對應(yīng)的cache.func.php

//緩存模型表
function cache_model()
{
cache_table(DB_PRE.&#39;model&#39;, &#39;*&#39;, &#39;&#39;, &#39;&#39;, &#39;modelid&#39;, 1);
}
//緩存分類表生成文件路徑是../data/cachecategory_catid.php
function cache_category()
{
cache_table(DB_PRE.&#39;category&#39;, &#39;*&#39;, &#39;&#39;, &#39;&#39;, &#39;listorder,catid&#39;, 1);
}

緩存類別表生成路徑

../data/cache/type_typeid.php
function cache_type()
{
cache_table(DB_PRE.&#39;type&#39;, &#39;*&#39;, &#39;&#39;, &#39;&#39;, &#39;listorder,typeid&#39;, 1);
}
//緩存地區(qū)列表

生成路徑:../data/cache/area_areaid.php

function cache_area()
{
cache_table(DB_PRE.&#39;area&#39;, &#39;*&#39;, &#39;&#39;, &#39;&#39;, &#39;listorder,areaid&#39;, 1);
}
//緩存用戶組表
//生成路徑:../data/cache member_grounp_group_id.php
function cache_member_group()
{
cache_table(DB_PRE.&#39;member_group&#39;, &#39;*&#39;, &#39;&#39;, &#39;&#39;, &#39;groupid&#39;, 1);
cache_table(DB_PRE.&#39;member_group&#39;, &#39;*&#39;, &#39;name&#39;, &#39;&#39;, &#39;groupid&#39;, 0);
}
//緩存角色表
//生成路徑:../data/cache/role_roleid.php
function cache_role()
{
cache_table(DB_PRE.&#39;role&#39;, &#39;*&#39;, &#39;name&#39;, &#39;&#39;, &#39;listorder,roleid&#39;);
}
//緩存作者表
//生成路徑:../data/cache/author_authorid.php
function cache_author()
{
cache_table(DB_PRE.&#39;author&#39;, &#39;*&#39;, &#39;name&#39;, &#39;&#39;, &#39;listorder,authorid&#39;, 0, 100);
}
function cache_keyword()
{
cache_table(DB_PRE.&#39;keyword&#39;, &#39;*&#39;, &#39;tag&#39;, &#39;&#39;, &#39;listorder,usetimes&#39;, 0, 100);
}
function cache_copyfrom()
{
cache_table(DB_PRE.&#39;copyfrom&#39;, &#39;*&#39;, &#39;&#39;, &#39;&#39;, &#39;listorder,usetimes&#39;, 0, 100);
}
function cache_pos()
{
cache_table(DB_PRE.&#39;position&#39;, &#39;*&#39;, &#39;name&#39;, &#39;&#39;, &#39;listorder,posid&#39;, 0);
}

PHP中文網(wǎng),大量的免費PHPCMS教程,歡迎在線學(xué)習!

The above is the detailed content of How are phpcms v9 cache files generated?. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

PHP Tutorial
1488
72
How to jump to the details page in phpcms How to jump to the details page in phpcms Jul 27, 2023 pm 05:23 PM

How to jump to the details page in phpcms: 1. Use the header function to generate a jump link; 2. Loop through the content list; 3. Get the title and details page link of the content; 4. Generate a jump link.

What framework is phpcms? What framework is phpcms? Apr 20, 2024 pm 10:51 PM

PHP CMS is a PHP-based open source content management system for managing website content. Its features include ease of use, powerful functionality, scalability, high security, and free open source. It can save time, improve website quality, enhance collaboration and reduce development costs, and is widely used in various websites such as news websites, blogs, corporate websites, e-commerce websites and community forums.

Isn't phpcms free? Isn't phpcms free? Mar 01, 2023 am 10:24 AM

phpcms is not completely free. phpcms is an open source cms system, but open source does not mean free. It has two versions: free version and commercial version. The free version is limited to personal non-commercial use, while the commercial version requires purchasing a license; individuals can use it for research, and if it is commercial application , you need to pay a certain fee.

WeChat Login Integration Guide: PHPCMS Practical Combat WeChat Login Integration Guide: PHPCMS Practical Combat Mar 29, 2024 am 09:18 AM

Title: WeChat Login Integration Guide: PHPCMS in Action In today’s Internet era, social login has become one of the essential functions of a website. As one of the most popular social platforms in China, WeChat’s login function is also used by more and more websites. This article will introduce how to integrate the WeChat login function in the PHPCMS website and provide specific code examples. Step 1: Register a WeChat Open Platform Account First, we need to register a developer account on the WeChat Open Platform and apply for the corresponding development permissions. Log in [WeChat open platform]

PHPCMS username security setting strategy revealed PHPCMS username security setting strategy revealed Mar 14, 2024 pm 12:06 PM

PHPCMS user name security setting strategy revealed In website development, user account security has always been an aspect that developers attach great importance to. The security settings of the username are also crucial, because the username is not only the user's login credentials, but may also expose the user's personal information and even cause security risks. This article will reveal the username security setting strategy in PHPCMS and give specific code examples for developers to refer to. 1. Prevent common usernames. In order to improve the security of usernames, developers should prevent users from using excessive

What does phpcms mean? What does phpcms mean? Apr 20, 2024 pm 10:39 PM

PHPCMS is a free and open source content management system (CMS) that features: open source, modularity, flexibility, user-friendliness and community support. It can be used to create various types of websites, including corporate websites, e-commerce websites, blogs, and community forums. Technical requirements include: PHP 5.6 or higher, MySQL, MariaDB or PostgreSQL database, and Apache or Nginx web server.

What versions of phpcms are there? What versions of phpcms are there? Jun 14, 2023 pm 01:13 PM

There are two well-known versions of phpcms, namely: 1. phpCMS4, which supports custom URL rules. The website management background is beautiful and easy to use, and has many front-end plug-ins, which can freely expand functions; 2. phpCMS2008R1, which supports multi-language, multi-site management, and page The manager is convenient, flexible, very lightweight, and runs fast.

What database does phpcms use? What database does phpcms use? Feb 21, 2023 pm 06:57 PM

phpcms uses mysql database. phpcms is a PHP open source website management system, developed using PHP+MYSQL as the technical basis. PHPCMS V9 adopts OOP method to build the basic operating framework. The supported PHP version is PHP5 and above, and the supported MYSQL version is MySql 4.1 and above.

See all articles