Thinkphp static cache usage analysis

不言
Release: 2023-03-30 08:42:01
Original
1602 people have browsed it

This article mainly introduces the use of static cache in thinkphp. It analyzes the configuration method and related operation techniques of static cache in more detail. It has certain practical value. Friends who need it can refer to this article.

A more detailed analysis of thinkphp's static cache usage. 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 to directly call 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
Copy after login

Set the generated static page saving path:

Copy code The code is as follows:

'HTML_PATH' =>'__APP__/html'
Copy after login

Set the default cache validity time:

Copy code The code is as follows:

'HTML_CACHE_TIME'=>'60'
Copy after login

Rules for reading static pages

Copy code The code is as follows:

'HTML_READ_TYPE'=>0
Copy after login

'HTML_READ_TYPE is set to 0, which means that when accessing this cached operation, the operation reads the static cached 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.

Next we need 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 Code The 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. The operation name is divided into three forms.

1. If you only write the operation name, it will be for all modules under the project. An operation name is cached.

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}, _GET _REQUEST _SERVER _SESSION _COOKIE The value ($_xxx) is 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.

Related recommendations:

Use thinkphp’s own method to generate static html files

The above is the detailed content of Thinkphp static cache usage analysis. For more information, please follow other related articles on the PHP Chinese website!

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