The principle and caching process of MySQL database operation using Memcache cache

Source: Internet
Author: User

Reprinted from the script house http://www.jb51.net/article/51831.htm busy squirrel

For large sites such as Facebook,ebay and other sites, if there is no memcache as the intermediate cache layer, data access is not possible feel all, for the general site, as long as there is a separate server, can be configured through Memcache to improve site access speed and reduce database pressure, This paper mainly discusses the process relationship between Memcache and MySQL database interaction process, understanding the role of intermediate buffer layer of memcache, so as to understand the memcache mechanism principle deeply.

Memcache and MySQL Interactive flowchart

For example, the traditional query method is to query the database directly, the database will return the results to the query statement, and when there is memcache intermediate cache layer, the query is memcache cache data, the following detailed understanding memcache various types of data operation principle:

1. Query data (select), first through the specified key query (get) memcache intermediate cache layer data, if there is relative data, then directly obtain the data results, the query process does not need to query the database. If it does not exist, query the MySQL database and store the query results in memcache cache data as key corresponding to value, and then return the result to the query statement.
2. Update the data (update), first updating the data, and then delete the associated memcache data (delete).
3. Add the data (add), first delete the relevant cache data, and then increase the data.
4. Delete data, delete data, and delete memcache data.

The main memcache methods for MySQL data manipulation are as follows:

1. Get: Get (Key)
2. Settings: Set (key, value [, expiry])
3. Deletion: Delete (key [, TIME])

Instance:
Suppose a post, get the value of the post ID 2009, its memcache and MySQL interaction process as follows:

$key = ' Biuuu_thread_ ';//key prefix $cachetime = 100;//Cache valid time (seconds) $id =;

Memcache Basic Operating Procedures

1. Query: $result = Get ($key. $id); If $result is empty, query the MySQL database and set ($key. $id, $value, 0, $cachetime)
2. Update: Delete ($key. $id);
3. Add: Delete ($key. $id);
4. Deletion: Delete ($key. $id);

Through the intuitive diagram and the instance should have a basic grasp of memcache and MySQL interaction, in fact, for the application, is basically enough, but if you want to relate to the namespace and other relatively complex situations, memcache operation will be different, but regardless of what kind of operation, Still can not be inseparable from the basic Operation command, because this is Memcache Foundation, mainly discusses Memcache and MySQL interactive operation flow, when memcache principle is clear, memcache basic operation is so simple.

The principle and caching process of MySQL database operation using Memcache cache

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.