Overview
1. meaning
The data is placed in the cache and can be obtained directly from the cache for a specified period of time, avoiding stress on the database, etc.
2. Procedure
Set up:
HttpRuntime.Cache.Insert (CacheKey, objobject,null,absoluteexpiration,slidingexpiration);
Read:
httpruntime.cache["Name"]
Demoprotected void Page_Load (object sender, EventArgs e) {//cache is a globally shared DataTable dt = (Dat aTable) httpruntime.cache["persons"];//If the cache does not, then go to the database query //This can reduce the pressure on the database server
if (dt = = null) { dt = Sqlhelper.executequery ("SELECT * from T_persons"); //Storage cache, expires after 30 seconds HttpRuntime.Cache.Insert ("persons", DT, NULL, DateTime.Now.AddSeconds (30), TimeSpan.Zero); } repeater1.datasource = DT; Repeater1.databind (); }
ASP. NET cache (cache)-asp. NET Trivia (2)