Please note that the system performance is degraded due to null cached in High-concurrency systems.

Source: Internet
Author: User

[ArticleAuthor: Sun Li link: http://www.cnblogs.com/sunli/ updated by: 2010-07-13]

General Cache Usage

When we use cache in applications, it is likely to use the followingCodeIndicates the logic. Obtain the cached data first.

Query the database or obtain data in other ways, and store the data in the cache to return data.

 

Code

  //  The Code cannot be executed directly, but it is used to express the logic.  

Data = Cache. Get (key );
If (Data = Null | ! Isvalid (data )){
SQL = " Select ...... " ;
Data = DB. Query (SQL ); // Data may be null
If (Data ){
Cache. Set (Key, Data, expire );
}
}
Return Data;

 

The above code runs very well in many cases, which is also used by many people.

Problem

If the key content does not exist in the database, the data in the code above is always null and there is no data in the cache, if the request for this key suddenly becomes very large (in many cases, for example, a wrong link request does not have data), a large number of requests will bypass the cache, direct access to the back-end database will cause a lot of pressure, and it is difficult to analyze the cause of the problem, because you think you have added the cache.

If the data volume is large and the access volume is large, the system may crash.

Solution

The solution to this problem is to cache null when the database queries null.

For example, if the database returns a list, we can store an empty list to process the cache. set (key, new list (), expire); of course, depending on the situation, you can also use other methods.

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.