Introduction: This is a detailed page for simple configuration and use of thinkphp static cache. It introduces PHP, related knowledge, skills, experience, and some PHP source code.
Class = 'pingjiaf' frameborder = '0' src = 'HTTP: // biancheng.dnbc?info/pingjia.php? Id = 327019 'rolling = 'no'>
Reference Source: http://www.javaeye.com/topic/451699
According to thinkphp official manual: thinkphp has built-in static cache class, and implements configurable static cache by defining static cache rules.
Enable static cache:
Thinkphp official manual
To use the static cache function for reference, you must enable the html_cache_on parameter and add the static cache rule file htmls. php under the project configuration directory. Both are indispensable. Otherwise, the static cache will not take effect.
Add the following to the configuration file conf \ config. php's Array:
'Html _ cache_on '=> true, // enable static cache 'html _ path' =>' _ app _/html ', // static cache file directory, html_path can be set arbitrarily. Here it is set to the newly created HTML directory under the current project.
Static rule definition, written in the official thinkphp Manual:
Return array ('actionname' => array ('static rule', 'static cache status', 'additional rule'), // The first 'modulename: actionname' => array ('static rule', 'static cache validity period ', 'additional rule'), // type 2' * '=> array ('static rule ', 'static cache validity status', 'additional rule'), // The third type... Static rules for more operations)
The first type of reference is to define global static operation rules. For example, to define static rules for all read operations: 'read' => array ('{ID}', '60 ')
{ID} indicates that $ _ Get ['id'] is the static cache file name, and the second parameter indicates that the cache is 60 seconds.
The second is to define the static rules for operations of a module. For example, we need to define the read operations of the blog module for static cache.
'Blog: read' => array ('{ID}',-1 ).
The third method is to define global static cache rules, which are used in special cases and are applicable to any module operations, such
'*' => Array ('{$ _ server. request_uri | MD5}'), which is cached based on the current URL.
Here I write in the static cache rule file htmls. php:
<? PHP return array ('gethtml' => array ('{: Action}',-1), //-1 indicates permanent cache);?>
The above static cache rules indicate that the static rules for defining all gethtml operations are: 'gethtml' => array ('{: Action}',-1 ).
{: Action} indicates that the current operation name is the static cache file name.
In\ Lib \ action \ indexaction. Class. phpFile write:
<? PHP class indexaction extends action {// The gethtml.shtml public function gethtml () {header ('content-type: text/html; charset = UTF-8 ') is generated under the current HTML directory '); $ this-> assign ('title', 'generate HTML file'); $ this-> assign ('info', 'generate HTML file '); $ this-> display () ;}}?>
In\ TPL \ Default \ Index \ gethtml.htmlWrite:
<! Doctype HTML public "-// W3C // dtd html 4.0 transitional // en"> <HTML>
Enter the following in the browser:Http: // 127.0.0.1/MyApp/index. php/index/gethtmlTo see the expected page.
After the page is refreshed, the address bar of the browser changes as follows:
PS: If Apache, Firefox, and opera files are used, they may not support SHTML files. in the conf file, find "addtype text/html. shtml "," addoutputfilter implements des. shtml, remove the previous.
More articles on "simple configuration and use of thinkphp static cache"
Love J2EE follow Java Michael Jackson video station JSON online tools
Http://biancheng.dnbcw.info/php/327019.html pageno: 12.