In this paper, the static cache usage of thinkphp is analyzed in detail. Share to everyone for your reference. The specific analysis is as follows:
Thinkphp has a built-in static cache function, saying that static caching may not be very good for my rookie. In fact, the static cache is the thinkphp of an operation to display the page generated an HTML file saved in the path of the setting, when the user again access, if the cache does not expire, then this operation will no longer execute the PHP program below it, but directly invoke the generated HTML cache file. To use a static cache, you need to add the static cache rule file htmls.php under the project configuration directory __app__/conf, and you need to open the static cache in the configuration file:
The code is as follows:
' Html_cache_on ' =>true
To set a static page save path that has been generated:
The code is as follows:
' Html_path ' = ' __app__/html '
To set the default cache validity time:
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 accessing this cached operation, the operation reads the static cache page display. The URL path is the path to the operation. If set to 1, when the operation is accessed, it redirects to the static page. The URL is the cache file path.
The next step is to cache the rules, that is, to set up what we want to do to statically cache, cache the name of the HTML, and cache time,
The code is as follows:
Return Array ("Action name" =>array ("HTML static file name to generate", "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 different forms.
1. If you write only the name of the operation, it is the operation name of all the modules under the project cache.
2. Module Name: The operation name, which means that only the operation under the module is cached.
3. ' * ' indicates that all operations are cached. Generate the name of the static file, you can have the current module name {: module}, the current operation name {: Action},_get _request _server _session _cookie value ($_xxx) to set . where the $_get[' xxx ' parameter can be represented directly with {XXX}. If the file name contains "/" then the system will create a new directory in the Save directory, such as {: Module}/{:action}, the system will create a directory named after the current module name in the __app__/html directory, and then generate an HTML file named after the current operation name. Cache expiration, in seconds, set to 1 for permanent caching, and the rule for generating file names is to rename the generated static file through a function, such as MD5.
It is hoped that this article will be helpful to everyone's thinkphp framework design.