Tips for using PHP cache technology to share

Source: Internet
Author: User
Keywords Tips for using PHP cache technology to share

The application of PHP cache technology is quite common, perhaps some people also do not understand this technology, we now give you a detailed introduction of the PHP cache technology related application skills.

The pros and cons of several mainstream PHP frameworks
Summarize PHP code escaping related methods
Introduction to the specific use method of the PHP rounding function
Explanation of the specific meanings of PHP external variables
PHP Tips for developing efficient web systems
In most cases, our site uses a database as a container for site data storage. When you execute an SQL query, the typical process is to connect database, prepare SQL query, send query to database, get database return results, and close the database connection. However, some of the data in the database is completely static or less frequent, and the cache system can be stored in a faster storage system by caching the results of the SQL query, thus avoiding the frequent operation of the database and greatly improving the program execution time, and the cached query results allow you to process it later.

Universally used PHP caching technology

Data Caching for PHP cache technology:

In this case, the data cache refers to the database query cache, each time access to the page, will detect the corresponding cache data is present, if not exist, connect to the database, get the data, and the query results are serialized and saved to the file
, the same query results are obtained directly from the cache file.

PHP Cache Technology 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 caching classes on the Web typically have this feature)

Memory Cache of PHP cache technology:

Not in the introduction, not to be discussed in this article, just briefly mention:
Memcached is a high-performance, distributed memory object caching system for reducing database load and increasing access speed in dynamic applications.
Dbcached is a distributed key-value database memory cache system based on Memcached and Nmdb.

Although the above cache technology can be a good solution to the problem of frequently querying the database, but its shortcomings in the data is not timeliness, below I give me in the project commonly used methods:

PHP Cache Technology 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.
Set time does not determine whether the data to be updated, over the set time and then update the cache. The above is only suitable for use when the timeliness requirements are not high, otherwise please see below.

The content of PHP cache technology triggers the cache:

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

Here we can see that when there is a lot of data that needs to be updated frequently, the last involves disk read and write operations. How to solve it? In my daily projects, I usually do not cache everything, but rather cache some of the things that are not constantly changing. However, in the case of heavy load, it is best to use shared memory as a caching system.

The PHP cache may be a bit of a solution here, but the downside is that because each request still has to be parsed by PHP, the efficiency problem is more severe in the case of a heavy load, in which case the static cache may be used.

Static caching of PHP cache technology

The static cache is referred to as the HTML cache, the HTML cache is generally not necessary to determine whether the data to be updated, because usually in the context of using HTML is often a page that does not change content frequently. Update the data when the HTML is also forced to update it.

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