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]