Thinkphp static cache usage analysis, thinkphp static cache_PHP tutorial

WBOY
Release: 2016-07-13 10:12:42
Original
971 people have browsed it

thinkphp static cache usage analysis, thinkphp static cache

This article analyzes the static cache usage of thinkphp in more detail. Share it with everyone for your reference. The specific analysis is as follows:

Thinkphp has a built-in static caching function. Static caching may not be easy to understand for a novice like me. In fact, static caching is to generate an HTML file from the page displayed by a certain operation of THINKphp and save it in the set path. When the user visits again, if the cache has not expired, then this operation will no longer execute the PHP program below it, but It is a direct call to the generated HTML cache file. To use static caching, you need to add the static caching rule file htmls.php under the project configuration directory __APP__/Conf, and you also need to turn on static caching in the configuration file:

Copy code The code is as follows:
'HTML_CACHE_ON'=>TRUE

Set the generated static page saving path:

Copy the code The code is as follows:
'HTML_PATH' =>'__APP__/html'
Set the default cache validity time:
Copy code The code is as follows:
'HTML_CACHE_TIME'=>'60'
Read static page Rules
Copy code The code is as follows:
'HTML_READ_TYPE'=>0
'HTML_READ_TYPE is set to 0, which is to access this cache When operating, the operation reads the static cache page for display. The URL path is the path of the operation. If set to 1, when accessing the operation, it will redirect to a static page. The URL is the cache file path.

The next step is to set some caching rules, that is, we need to set which operations we want to statically cache, the name of the cached HTML, and the cache time.

Copy codeThe code is as follows:
return array("Operation name"=>array("Name of HTML static file to be generated", "Set cache validity period", "Rules for generating file names") )
The "operation name" above is the operation that needs to be cached, and the operation name is divided into three forms.

1. If you only write the operation name, it will cache the operation name of all modules under the project.

2. Module name: operation name, which means that only the operation under this module will be cached.

3. '*' means caching all operations. The name of the generated static file can be the current module name {:module}, the current operation name {:action}, and the value of _GET _REQUEST _SERVER _SESSION _COOKIE ( $_xxx) to set. The $_GET['xxx'] parameter can be directly represented by {xxx}. If the file name contains "/", the system will create a new directory in the saving directory, such as {:module}/{:action}. The system will create a total of directories named after the current module name in the __APP__/html directory, and then An html file named after the current operation name is generated. The cache validity period is in seconds. Set to -1 to indicate permanent caching. The rule for generating file names is to rename the name of the generated static file through a certain function, such as md5.

I hope this article will be helpful to everyone’s ThinkPHP framework programming.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/919624.htmlTechArticleAnalysis of thinkphp's static cache usage, thinkphp static cache This article analyzes thinkphp's static cache usage in more detail. Share it with everyone for your reference. The specific analysis is as follows: thin...
Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!