Analysis of thinkphp static cache usage and thinkphp static cache. Thinkphp static cache usage analysis, thinkphp static cache This article analyzes in detail thinkphp static cache usage. Share it with you for your reference. The specific analysis is as follows: thin thinkphp static cache usage analysis, thinkphp static cache
This article gives a detailed analysis of thinkphp's static cache usage. Share it with you for your reference. The specific analysis is as follows:
Thinkphp has a built-in static cache function, saying that static cache may not be very easy for Cainiao like me. In fact, the static cache generates an HTML file from a page displayed by a THINKphp operation and stores it in the set path. when the user accesses the page again, if the cache does not expire, this operation will not execute the PHP program below it, but directly call the generated HTML cache file. To use static cache, you need to add the static cache rule file htmls. php under the project configuration directory/index. php/Conf. you also need to open the static cache in the configuration file:
The code is as follows:
'HTML _ CACHE_ON '=> TRUE
Set the path for saving generated static pages:
The code is as follows:
'HTML _ path' => '/index. php/html'
Set the default cache validity period:
The code is as follows:
'HTML _ CACHE_TIME '=> '60'
Rules for reading static pages
The code is as follows:
'HTML _ READ_TYPE '=> 0
'HTML _ READ_TYPE is set to 0, that is, when you access the cached operation, the operation reads the static cache page. The URL path is the path of this operation. if it is set to 1, it redirects to the static page when accessing this operation. The URL is the cache file path.
Next, we need some cache rules, that is, to set which operations we want to perform static cache, cache the HTML name, and cache time,
The code is as follows:
Return array ("Operation name" => array ("HTML static file name to be generated", "set cache validity period", "rules for generating file names "))
The above "operation name" is the operation to be cached, and the operation name is divided into three forms.
1. if only the operation name is written, the operation name of all modules under the project is cached.
2. module name: indicates that only the operation under this module is cached.
3. '*' indicates that all operations are cached. generate the static file name. you can add the current module name {: module}, the current operation name {: action }, set the value of _ GET _ REQUEST _ SERVER _ SESSION _ COOKIE ($ _ xxx. the $ _ GET ['XXX'] parameter can be expressed directly by {xxx. If the file name contains "/", the system creates a directory in the saved Directory. for example, the {: module}/{: action} system will be in/index. A directory named after the current module is created under the php/html directory, and an html file named after the previous operation is generated. the cache validity period is in seconds, -1 indicates permanent cache. The rule for generating file names is to rename the names of generated static files through a function, such as md5.
I hope this article will help you with ThinkPHP framework programming.
This article analyzes in detail the static cache usage of thinkphp. Share it with you for your reference. The specific analysis is as follows: thin...