Several caching mechanisms commonly used in PHP _php tutorial

Source: Internet
Author: User
Universal Cache Technology

Data cache: In this case, the data cache refers to the database query PHP cache mechanism, each time you visit the page, will first detect the corresponding cache data exists, if not exist, connect to the database, get the data, and the query results are serialized and saved to the file, Later, the same query results are obtained directly from the cache table or file.

The most widely used example is the search function of discuz, which caches the result ID into a table and searches the cache table the next time the same keyword is searched.

For a common method, multi-table association, the schedule of the contents of the array is saved to a field in the main table, the need for the array decomposition, the advantage is only read a table, the disadvantage is that two data synchronization will be more than a few steps, the database is always the bottleneck, with the hard disk speed, is the key point.

Page cache:

Each time you visit the page, will detect the corresponding cache page file exists, if not exist, connect to the database, get data, display the page and generate the cache page file at the same time, so the next visit to the page file will play a role. (the template engine and some common PHP caching mechanism classes on the web usually have this feature)

Time-Triggered cache:

Check that the file exists and that the timestamp is less than the expiration time of the setting, and if the timestamp of the file modification is greater than the current timestamp minus the expiration timestamp, then cache is used, otherwise the cache is updated.

Content-Triggered caching:

Forces the PHP cache mechanism to be updated when data is inserted or updated.

Static cache:

Static caching refers to static, directly generated HTML or XML and other text files, there is an update when re-generated once, suitable for the less changing pages, this does not say.

The above content is a code-level solution, I direct CP other framework, too lazy to change, the content is almost, very easy to do, and will be used together in several ways, but the following content is the server-side caching scheme, non-code level, to have multi-party cooperation to do

Memory Cache:

Memcached is a high-performance, distributed memory object PHP caching mechanism system for reducing database load and increasing access speed in dynamic applications.

Buffer for PHP:

There are eaccelerator, APC, Phpa,xcache, this is not to say, search a bunch of a bunch of, see for yourself, know that this thing is OK

MySQL cache:

This is also non-code level, the classic database is used in this way, look at the following running time, 0.09xxx and the like
I stick paragraph according to the Blue Guy modify the latter part of the My.ini bar, 2G MyISAM table can be around 0.05S, it is said that he changed back and forth for a year

Reverse proxy-based Web caching:

such as Nginx,squid,mod_proxy (Apache2 and above are divided into mod_proxy and Mod_cache)
Examples of Nginx

DNS Polling:

Bind is an open source DNS server software, this to say it is big, their own search, you know there is this thing on the line.
I know that there are chinacache and other major stations to do so, said the simple point is a multi-server, the same page or file cache to different servers, according to the North-South automatic resolution to the relevant server.

http://www.bkjia.com/PHPjc/478732.html www.bkjia.com true http://www.bkjia.com/PHPjc/478732.html techarticle Universal Caching Technology Data cache: The data cache referred to here refers to the database query PHP caching mechanism, each time you visit the page, will first detect the corresponding cache data exists, such as ...

  • Related Article

    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.