Analysis of thinkphp static cache usage

Source: Internet
Author: User
Analysis of thinkphp static cache usage
Thinkphp static cache usage, thinkphp static cache configuration method and operation skills, thinkphp built-in static cache function, you can directly call the generated HTML cache file, for a friend's reference.

Thinkphp static cache usage

Thinkphp has built-in static cache function. static cache is used to generate an HTML file on a page displayed by a THINKphp operation and save 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:

'HTML _ CACHE_ON '=> TRUE

Set the path for saving generated static pages:

'HTML _ path' => '/index. php/html'

Set the default cache validity period:

'HTML _ CACHE_TIME '=> '60'

Rules for reading static pages

'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.

Cache rule settings, which operations are statically cached, the names of the cached HTML, and the cache time are up, 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, if-1 is set to permanent cache, the file name generation rule is to rename the name of the generated static file through a function, such as md5.

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.