Using System;
Using System.Web;
<summary>
Cache-related action classes
Copyright (C) Maticsoft
</summary>
public class Datacache
{
<summary>
Gets the cache value of the current application specified CacheKey
</summary>
<param name= "CacheKey" ></param>
<returns></returns>
public static Object GetCache (String CacheKey)
{
System.Web.Caching.Cache Objcache = Httpruntime.cache;
return Objcache[cachekey];
}
<summary>
Sets the cache value for the current application to specify CacheKey
</summary>
<param name= "CacheKey" ></param>
<param name= "Objobject" ></param>
public static void Setcache (String CacheKey, Object Objobject)
{
System.Web.Caching.Cache Objcache = Httpruntime.cache;
Objcache.insert (CacheKey, objobject);
}
<summary>
Sets the cache value for the current application to specify CacheKey
</summary>
<param name= "CacheKey" ></param>
<param name= "Objobject" ></param>
public static void Setcache (String CacheKey, Object Objobject, 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 void RemoveCache (String CacheKey)
{
Try
{
System.Web.Caching.Cache _cache = Httpruntime.cache;
_cache. Remove (CacheKey);
}
Catch {}
}
<summary>
Removing all Caches
</summary>
public static void Removeallcache ()
{
System.Web.Caching.Cache _cache = Httpruntime.cache;
System.Collections.IDictionaryEnumerator cacheenum = _cache. GetEnumerator ();
while (Cacheenum.movenext ())
{
_cache. Remove (CacheEnum.Key.ToString ());
}
}
}
. NET WEB Cache