Home Backend Development PHP Tutorial Thinkphp static cache usage analysis

Thinkphp static cache usage analysis

Jun 06, 2018 pm 03:13 PM
thinkphp usage cache static

This article mainly introduces the use of static cache in thinkphp. It analyzes the configuration method and related operation techniques of static cache in more detail. It has certain practical value. Friends who need it can refer to this article.

A more detailed analysis of thinkphp's static cache usage. Share it with everyone for your reference. The specific analysis is as follows:

thinkphp has a built-in static caching function. Static caching may not be easy to understand for a novice like me. In fact, static caching is to generate an HTML file from 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 execute the PHP program below it, but It is to directly call 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:

Copy code The code is as follows :

'HTML_CACHE_ON'=>TRUE
Copy after login

Set the generated static page saving path:

Copy code The code is as follows:

'HTML_PATH' =>'__APP__/html'
Copy after login

Set the default cache validity time:

Copy code The code is as follows:

'HTML_CACHE_TIME'=>'60'
Copy after login

Rules for reading static pages

Copy code The code is as follows:

'HTML_READ_TYPE'=>0
Copy after login

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

Next we need some caching rules, that is, we need to set which operations we want to statically cache, the name of the cached HTML, and the cache time,

Copy Code The code is as follows:

return array("Operation name" =>array("Name of 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 be for all modules under the project. An operation name is cached.

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}, _GET _REQUEST _SERVER _SESSION _COOKIE The value ($_xxx) is 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, such as {: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.

Related recommendations:

Use thinkphp’s own method to generate static html files

The above is the detailed content of Thinkphp static cache usage analysis. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to run thinkphp project How to run thinkphp project Apr 09, 2024 pm 05:33 PM

To run the ThinkPHP project, you need to: install Composer; use Composer to create the project; enter the project directory and execute php bin/console serve; visit http://localhost:8000 to view the welcome page.

There are several versions of thinkphp There are several versions of thinkphp Apr 09, 2024 pm 06:09 PM

ThinkPHP has multiple versions designed for different PHP versions. Major versions include 3.2, 5.0, 5.1, and 6.0, while minor versions are used to fix bugs and provide new features. The latest stable version is ThinkPHP 6.0.16. When choosing a version, consider the PHP version, feature requirements, and community support. It is recommended to use the latest stable version for best performance and support.

How to view and refresh dns cache in Linux How to view and refresh dns cache in Linux Mar 07, 2024 am 08:43 AM

DNS (DomainNameSystem) is a system used on the Internet to convert domain names into corresponding IP addresses. In Linux systems, DNS caching is a mechanism that stores the mapping relationship between domain names and IP addresses locally, which can increase the speed of domain name resolution and reduce the burden on the DNS server. DNS caching allows the system to quickly retrieve the IP address when subsequently accessing the same domain name without having to issue a query request to the DNS server each time, thereby improving network performance and efficiency. This article will discuss with you how to view and refresh the DNS cache on Linux, as well as related details and sample code. Importance of DNS Caching In Linux systems, DNS caching plays a key role. its existence

How to run thinkphp How to run thinkphp Apr 09, 2024 pm 05:39 PM

Steps to run ThinkPHP Framework locally: Download and unzip ThinkPHP Framework to a local directory. Create a virtual host (optional) pointing to the ThinkPHP root directory. Configure database connection parameters. Start the web server. Initialize the ThinkPHP application. Access the ThinkPHP application URL and run it.

Which one is better, laravel or thinkphp? Which one is better, laravel or thinkphp? Apr 09, 2024 pm 03:18 PM

Performance comparison of Laravel and ThinkPHP frameworks: ThinkPHP generally performs better than Laravel, focusing on optimization and caching. Laravel performs well, but for complex applications, ThinkPHP may be a better fit.

How to install thinkphp How to install thinkphp Apr 09, 2024 pm 05:42 PM

ThinkPHP installation steps: Prepare PHP, Composer, and MySQL environments. Create projects using Composer. Install the ThinkPHP framework and dependencies. Configure database connection. Generate application code. Launch the application and visit http://localhost:8000.

How is the performance of thinkphp? How is the performance of thinkphp? Apr 09, 2024 pm 05:24 PM

ThinkPHP is a high-performance PHP framework with advantages such as caching mechanism, code optimization, parallel processing and database optimization. Official performance tests show that it can handle more than 10,000 requests per second and is widely used in large-scale websites and enterprise systems such as JD.com and Ctrip in actual applications.

Caching mechanism and application practice in PHP development Caching mechanism and application practice in PHP development May 09, 2024 pm 01:30 PM

In PHP development, the caching mechanism improves performance by temporarily storing frequently accessed data in memory or disk, thereby reducing the number of database accesses. Cache types mainly include memory, file and database cache. Caching can be implemented in PHP using built-in functions or third-party libraries, such as cache_get() and Memcache. Common practical applications include caching database query results to optimize query performance and caching page output to speed up rendering. The caching mechanism effectively improves website response speed, enhances user experience and reduces server load.

See all articles