This example describes the ASP.net cache processing class. Share to everyone for your reference. Specifically as follows:
asp.net cache processing class.
Usage:
Just Copy this code into a new class file (. cs) and add it to your ASP. NET website. One thing to keep in mind are that the data stored in ASP. NET Cache can being accessible across all sessions. So while creating a CacheID for the object to be stored, it must is unique (or it could be overwritten). I usually store the unique CacheID in the session and then the CacheID. (e.g. cachehandler.write (session["Mycachedata"], myData);)
The specific code is as follows:
Using System;
Using System.Collections.Generic;
Using System.Web.Caching;
Using System.Web; <summary>///This class reads/writes to ASP. NET Server Cache.
For the sake of///simplicity, the class writes objects to cache with no expirateion. Use the Remove () function to programmatically remove objects stored///from the server cache.
This class is created as a alternative to///storing large the session. </summary> public class Cachehandler {public static bool Write (string CacheID, Object data) {if HTTPC Ontext.
current = = null) return false;
if (CacheID = null | | cacheid.equals ("")) return false; HttpRuntime.Cache.Insert (CacheID, data, NULL, Cache.noabsoluteexpiration, Cache.noslidingexpiration, Cac
Heitempriority.notremovable, NULL);
return true;
public static Object Read (String CacheID) {if (httpcontext.current = null) return null; Return httpruntime.cache.gET (CacheID);
public static void Remove (String cacheid) {if (httpcontext.current = null) return;
if (CacheID = null | | cacheid.equals ("")) return;
HttpRuntime.Cache.Remove (CacheID);
}
}
I hope this article will help you with your asp.net programming.