Static cache usage of thinkphp

Source: Internet
Author: User
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 is to generate an HTML file on a page displayed by a THINKphp operation and save it in the set path.

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, add the static cache rule file htmls under the Directory _ APP _/Conf of the project configuration. php, you also need to open the static cache 'HTML _ CACHE_ON '=> TRUE.

Set the PATH for saving generated static pages to 'HTML _ path' => '_ APP _/html ', set the default cache validity period 'HTML _ CACHE_TIME '=> '60'. set the rules for reading static pages 'HTML _ READ_TYPE' => 0, and set 'HTML _ READ_TYPE to 0, 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, 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, {: module }/{: action} the system will create a directory named after the current module name under the _ APP _/html directory, and then generate an html file named after the previous operation name, cache validity period, in seconds. if it is set to-1, the cache is permanently cached. The rule for generating file names is to rename the names of generated static files 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.