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:
Set the generated static page saving 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.
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.