Using system;using system.collections.generic;using system.linq;using system.text;using System.Web;using System.Web.Caching; namespace utility{///<summary>//cache operation, default cache 1 min///</summary> public static class Cachehelper {static int cacheTime = 1; <summary>//Read cache entry///</summary>//<returns></returns> public Static Object Cachereader (String cacheKey) {return httpruntime.cache[cachekey]; }//<summary>//write cache entry///</summary> public static void Cachewriter (String CA Chekey, Object cachevalue, int cache_time = 0) {HttpRuntime.Cache.Insert (CacheKey, cachevalue, NULL, DateTime.Now.AddMinutes (cache_time <= 0? cachetime:cache_time), Cache.noslidingexpiratio n); }///<summary>//Remove specified cache entry///</summary> public static voidCacheRemove (String cachename) {HttpRuntime.Cache.Remove (cachename); }///<summary>//cache object Generic Implementation//</summary> public static T objectreader<t> (string cacheKey = null) where T:class {string cacheKey = typeof (T). GetHashCode () + stringhelper.tostring (CacheKey); var obj = Cachereader (cachekey) as T; return obj; }///<summary>//cache object Generic Implementation///</summary> public static void objectwriter<t& gt; (T cachevalue, string cacheKey = null, int cache_time = 0) where T:class {string Cachek ey = typeof (T). GetHashCode () + stringhelper.tostring (CacheKey); Cachewriter (CacheKey, Cachevalue, cache_time); } }}
C # Cache Action Classes