System.Web.Caching Simple Package class:
1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.Web.Caching;4 usingsystem.web;5 usingSystem.Collections;6 7 namespaceAPP. HttpCache8 {9 Public classCachehelperTen { One Private StaticCache cacheobj =Httpruntime.cache; A - /// <summary> - ///Simple Key,vlaue Write the /// </summary> - /// <param name= "key" ></param> - /// <param name= "value" ></param> - Public Static voidInsert (stringKeyObjectvalue) + { - Cacheobj.insert (key, value); + } A at /// <summary> - ///set an absolute expiration time - /// </summary> - /// <param name= "key" ></param> - /// <param name= "value" ></param> - /// <param name= "absoluteexpiration" ></param> in /// <param name= "slidingexpiration" ></param> - Public Static voidInsert (stringKeyObjectvalue, DateTime absoluteexpiration) to { +Cacheobj.insert (key, value,NULL, absoluteexpiration, cache.noslidingexpiration); - } the * /// <summary> $ ///Set Smooth expirationPanax Notoginseng /// </summary> - /// <param name= "key" ></param> the /// <param name= "value" ></param> + /// <param name= "slidingexpiration" ></param> A Public Static voidInsert (stringKeyObjectvalue, TimeSpan slidingexpiration) the { +Cacheobj.insert (key, value,NULL, Cache.noabsoluteexpiration, slidingexpiration); - } $ $ /// <summary> - ///Get Vlaue - /// </summary> the /// <param name= "key" ></param> - /// <returns></returns>Wuyi Public Static ObjectGet (stringkey) the { - returnCacheobj.get (key); Wu } - About /// <summary> $ ///Get Vlaue - /// </summary> - /// <param name= "key" ></param> - /// <returns></returns> A Public StaticT get<t> (stringkey) + { the varv =Cacheobj.get (key); - returnv = =NULL?default(t): (t) convert.changetype (V,typeof(T)); $ } the the /// <summary> the ///Remove Key the /// </summary> - /// <param name= "key" ></param> in /// <returns></returns> the Public Static voidDelete (stringkey) the { About Cacheobj.remove (key); the } the the /// <summary> + ///Remove Key - /// </summary> the /// <param name= "key" ></param>Bayi /// <returns></returns> the Public Static ObjectRemove (stringkey) the { - returnCacheobj.remove (key); - } the the /// <summary> the ///Remove Key the /// </summary> - /// <param name= "key" ></param> the /// <returns></returns> the Public StaticT remove<t> (stringkey) the {94 varv =Cacheobj.remove (key); the returnv = =NULL?default(t): (t) convert.changetype (V,typeof(T)); the } the 98 /// <summary> About ///number of cache keys - /// </summary>101 Public Static intKeycount102 {103 Get104 { the returnCacheobj.count;106 }107 }108 109 /// <summary> the ///all key111 /// </summary> the Public StaticArrayList Keyall ()113 { the vararr =NewArrayList (); the varitem =cacheobj.getenumerator (); the while(item. MoveNext ())117 {118 arr. ADD (item. Key);119 } - returnarr;121 }122 123 /// <summary>124 ///Clear All caches the /// </summary>126 Public Static voidDeleteAll ()127 { - varitem =cacheobj.getenumerator ();129 while(item. MoveNext ()) the {131 Cacheobj.remove (item. Key.tostring ()); the }133 }134 }135}View Code
System.Web.Caching