public void ProcessRequest (HttpContext context) {//context. Response.ContentType = "Text/plain"; Context. Response.Write ("Hello World"); if (context. Request["action"] = NULL) {switch (context. Request["Action"]. ToString ()) {case ' Add ': Add (); break; Case "SelectCount": SelectCount (); Break Case "File": File (); Break Default:break; }}} private void file () {FileInfo fi = new FileInfo ("Fuct.txt"); StreamWriter SW = new StreamWriter (FI. FullName); Sw. WriteLine (New Random (). Next (100)); Sw. Flush (); Sw. WriteLine (New Random (). Next (100)); Sw. Flush (); Sw. Close (); Sw. Dispose (); StreamReader sr = new StreamReader (FI. FullName); String word = Sr. ReadLine (); Sr. ClosE (); Sr. Dispose (); String json = "{\" word\ ": \" "+ Word +" \ "}"; HttpContext.Current.Response.Write (JSON); } private void Add () {TimeSpan ts = new TimeSpan (11, 0, 0); String value = httpcontext.current.request["value"]. ToString (); string key = httpcontext.current.request["Key"]. ToString (); System.Web.Caching.Cache Objcache = Httpruntime.cache; FileInfo fi = new FileInfo ("Fuct.txt"); System.Web.Caching.CacheDependency file = new System.Web.Caching.CacheDependency (FI. FullName); Objcache.insert (key, value, file, DateTime.MaxValue, TS, System.Web.Caching.CacheItemPriority.NotRemovable, NULL); System.Web.Caching.Cache AA = HttpContext.Current.Cache; HttpContext.Current.Response.Write (AA. Count); } private void SelectCount () {System.Web.Caching.Cache AA = HttpContext.Current.Cache; Httpcontext.curreNt. Response.Write (AA. Count); } public bool IsReusable {get {return false; } }
The last few interviews have been asked to cache this thing, so take the time to simply learn the next cache to store some
And then tested the CacheDependency in the cache, which is the cache dependency. Once a dependency changes the cache, it can be used to store some configuration information in general configuration to XML and then cache this XML once the configuration modifies the cache and needs to be read again
Test the next with a txt to use as a dependency manually in the folder to modify the seemingly unaffected but use the program to modify the immediate effect of the cache was cleared
. NET Cache Learning Notes