Seamless cache reads: Dual storage cache Policy

Source: Internet
Author: User
Keywords caching nbsp;
Tags access business cache caching data data statistics data structure get
Up

A recent optimization of data statistics for the web, but due to the large amount of data, the execution of a SQL statistics for a long time (generally 700ms is normal).

The normal practice is to add a cache.

But at the same time the business requires this data to be updated for up to 1 minutes, and there may be more variation in that data (and the original system is not easy to expand).

That is, caching is 1 minutes of failure to recalculate, and the user access to the page is very frequent, if the use of the general cache so the user experience is poor and can easily cause timeouts.

Bearing

To see the above requirements, the first to enter my brain is the previous game to touch the DDraw double buffer display.

When the first frame is displayed, the second frame is being computed, so that the reading and calculation can be separated, and the read-time calculation is avoided and the user experience is improved.

I think of course we can also use this approach in the caching strategy, but this is a trade-off in terms of space in exchange for time, because not all of the time is worth it, but here I 211.html "> I think this is the best way to do it."

Note: In order to be able to demonstrate, the cache in this article is stored in the form of IEnumerable, of course, the principle of this article can also be applied in Webcache.

Here I use the following data structure as a storage unit:

Namespace Chcache {
///
Caching media
///
public class Medium {
///
Primary storage Media
///
Public object Primary {get; set;}
///
Secondary storage media
///
Public object Secondary {get; set;}
///
Whether primary storage is being used
///
public bool Isprimary {get; set;}
///
is updating
///
public bool Isupdating {get; set;}
///
Whether the update is complete
///
public bool isupdated {get; set;}
}
}

With this data structure, we can implement two storage. Using some reading and writing strategies, we can realize the caching method mentioned above.

Continue >> Next [1th] [page 2nd] [3rd]
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.