thinkphp Static cache usage Analysis _php instance

Source: Internet
Author: User

In this paper, the static caching 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 caching feature, saying that static caching may not be a good idea for a rookie like me. In fact, static caching is the thinkphp of an operation to display the page generated an HTML file saved in the set path, 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 static caching, you need to increase 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:

Copy Code code as follows:
' Html_cache_on ' =>true

To set the saved path for a static page that has already been generated:

Copy Code code as follows:
' Html_path ' => ' __app__/html '
To set the default cache validity time:
Copy Code code as follows:
' Html_cache_time ' => ' 60 '
Rules for reading static pages
Copy Code code 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 you access the operation, it redirects to the static page. The URL is the cached file path.

The next step is to cache the rules, which is to set what we want to do with static caching, caching HTML names, and caching time,

Copy Code code as follows:
Return Array ("Operation name" =>array ("HTML static file name to generate", "set cache validity period", "Rule generating file name"))
The above "operation name" is required to cache the operation, the operation name is divided into three different forms.

1. If you write only the name of the operation, that is to cache the operation name of all modules below the project.

2. Module Name: operation name, which means caching only the operation below the module.

3. ' * ' indicates that all operations are cached. Generates a static file name that can be set with the current module name {: module}, and the current action name {: Action},_get _request _server _session _cookie value ($_xxx) where the $_get[' xxx ' parameter can be represented directly by {XXX}. If the file name contains "/" then the system creates a new directory in the Save directory, such as the {: Module}/{:action} system creates a total directory named after the current module name in the __app__/html directory, and then generates an HTML file named after the current operation name, Cache expiration, in seconds, set to 1 for permanent caching, the rule for generating file names is to rename the generated static files by a function, such as MD5.

I hope this article will be helpful to everyone's thinkphp framework program design.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.