usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingsystem.web;usingSystem.Collections;namespacecommon{ Public Static classCacheManager {/// <summary> ///Get data cache/// </summary> /// <param name= "CacheKey" >Key</param> Public Static ObjectGetCache (stringCacheKey) {System.Web.Caching.Cache Objcache=Httpruntime.cache; returnObjcache[cachekey]; } /// <summary> ///setting up the data cache/// </summary> Public Static voidSetcache (stringCacheKey,Objectobjobject) {System.Web.Caching.Cache Objcache=Httpruntime.cache; Objcache.insert (CacheKey, objobject); } /// <summary> ///setting up the data cache///CacheKey///Objobject///Expires min/// </summary> Public Static voidSetcache (stringCacheKey,ObjectObjobject,intexpires) {System.Web.Caching.Cache Objcache=Httpruntime.cache; Objcache.insert (CacheKey, Objobject,NULL, DateTime.MaxValue,NewTimeSpan (0, Expires,0), System.Web.Caching.CacheItemPriority.NotRemovable,NULL); } /// <summary> ///setting up the data cache/// </summary> Public Static voidSetcache (stringCacheKey,ObjectObjobject, DateTime absoluteexpiration, TimeSpan slidingexpiration) {System.Web.Caching.Cache Objcache=Httpruntime.cache; Objcache.insert (CacheKey, Objobject,NULL, absoluteexpiration, slidingexpiration); } /// <summary> ///remove the specified data cache/// </summary> Public Static voidRemoveCache (stringCacheKey) {System.Web.Caching.Cache _cache=Httpruntime.cache; _cache. Remove (CacheKey); } /// <summary> ///Removing all caches/// </summary> Public Static voidRemoveallcache () {System.Web.Caching.Cache _cache=Httpruntime.cache; IDictionaryEnumerator Cacheenum=_cache. GetEnumerator (); while(Cacheenum.movenext ()) {_cache. Remove (CacheEnum.Key.ToString ()); } } }}
C # CacheManager Cache management