Thinkphp static cache usage, thinkphp static cache configuration methods and operating techniques, thinkphp has a built-in static cache function, which can directly call the generated HTML cache file. Friends who need it can refer to it.
thinkphp static cache usage Thinkphp has a built-in static caching function. Static caching is to generate an HTML file for the page displayed by a certain operation of THINKphp and save it in the set path. When the user visits again, if the cache has not expired, then this operation will no longer be executed. The following PHP program instead directly calls the generated HTML cache file. To use static caching, you need to add the static caching rule file htmls.php under the project configuration directory __APP__/Conf, and you also need to turn on static caching in the configuration file: 'HTML_CACHE_ON'=>TRUESet the generated static page saving path: 'HTML_PATH' =>'__APP__/html'Set the default cache validity time: 'HTML_CACHE_TIME'=>'60'Rules for reading static pages 'HTML_READ_TYPE'=>0'HTML_READ_TYPE is set to 0, which means that when accessing this cached operation, the operation reads the static cached page for display. The URL path is the path of the operation. If set to 1, when accessing the operation, it will redirect to a static page. The URL is the cache file path. Cache rule settings, which operations are statically cached, the name of the cached HTML, and the cache time, return array("Operation name" =>array("Name of the HTML static file to be generated", "Set cache validity period", " Rules for generating file names") ) The "operation name" above is the operation that needs to be cached. The operation name is divided into three forms. 1. If you only write the operation name, it will cache the operation name of all modules under the project. 2. Module name: operation name, which means that only the operation under this module will be cached. 3. '*' means caching all operations. The name of the generated static file can be the current module name {:module}, the current operation name {:action}, and the value of _GET _REQUEST _SERVER _SESSION _COOKIE ($_xxx) To set. The $_GET['xxx'] parameter can be directly represented by {xxx}. If the file name contains "/", the system will create a new directory in the saving directory. For example, {:module}/{:action}, the system will create a total of directories named after the current module name in the __APP__/html directory, and then An html file named after the current operation name is generated. The cache validity period is in seconds. Set to -1 to indicate permanent caching. The rule for generating file names is to rename the name of the generated static file through a certain function, such as md5. |