[Csharp] /// <summary> /// data cache class /// </summary> public class DataCache {# region cache depends on the file web. config private static string _ webconfigfile = string. empty; // <summary> // cache the web of dependent files. config // </summary> public static string webconfigfile {get {if (_ webconfigfile = string. empty) _ webconfigfile = HttpContext. current. server. mapPath ("/web. config "); return _ webconfigfile ;}} # endregion # region Delete cache // <summary> // Delete cache // </summary> // <param name = "CacheKey"> key </param> public static void DeleteCache (string CacheKey) {HttpRuntime. cache. remove (CacheKey );} # endregion # region obtain the cache /// <summary> /// obtain the cache /// </summary> /// <param name = "CacheKey"> key </param> /// <returns> </returns> public static object GetCache (string CacheKey) {return HttpRuntime. cache [CacheKey];} # endregion # region simple insert cache // <summary> /// simple insert cache /// </summary> /// <param name = "CacheKey"> key </param> // <param name = "objObject"> data </param> public static void SetCache (string CacheKey, object objObject) {HttpRuntime. cache. insert (CacheKey, objObject );} # endregion # insert cache data with an expiration time in region /// <summary> /// insert cache data with an expiration time /// </summary> /// <param name = "CacheKey"> key </param> // <param name = "objObject"> data </param> // <param name = "absoluteExpiration"> expiration time </param> /// <param name = "slidingExpiration"> scheduling parameters, if null is passed, the scheduling is disabled. </param> public static void SetCache (string CacheKey, object objObject, DateTime absoluteExpiration, TimeSpan slidingExpiration) {if (slidingExpiration = null) slidingExpiration. noSlidingExpiration; HttpRuntime. cache. insert (CacheKey, objObject, null, absoluteExpiration, slidingExpiration);} # endregion # region inserts cache data, specifying the number of seconds to cache /// <summary> /// Insert cache data, specify the number of seconds to cache /// </summary> /// <param name = "CacheKey"> cache key </param> /// <param name = "objObject"> cached data </param> /// <param name = "seconds"> cache seconds </param> /// <param name = "slidingExpiration"> If null is passed, it is disabled. schedule expiration </param> public static void SetCacheSecond (string CacheKey, object objObject, int seconds, TimeSpan slidingExpiration) {DateTime absoluteExpiration = DateTime. now. addSeconds (seconds); if (slidingExpiration = null) slidingExpiration = Cache. noSlidingExpiration; HttpRuntime. cache. insert (CacheKey, objObject, null, absoluteExpiration, slidingExpiration);} # endregion # cache of region dependent files, if the file is not modified, it will not expire. // <summary> // the cache of the dependent file, the file will not expire if it is not modified. // </summary> // <param name = "CacheKey"> key </param> // <param name = "objObject"> data </param> // <param name = "depfilename"> dependent file, call the variables in DataCache </param> public static void SetCacheDepFile (string CacheKey, object objObject, string depfilename) {// cache dependent object System. web. caching. cacheDependency dep = new System. web. caching. cacheDependency (depfilename); System. web. caching. cache objCache = HttpRuntime. cache; objCache. insert (CacheKey, objObject, dep, System. web. caching. cache. noAbsoluteExpiration, // never expires System. web. caching. cache. noSlidingExpiration, // disable the adjustable expiration System. web. caching. cacheItemPriority. default, null) ;}# endregion}