Using System;
Using System.Web;
Using System.Collections;
Namespace Dotnet.utilities
{
public class Cachehelper
{
<summary>
Get data cache
</summary>
<param name= "CacheKey" > Keys </param>
public static Object GetCache (String CacheKey)
{
System.Web.Caching.Cache Objcache = Httpruntime.cache;
return Objcache[cachekey];
}
<summary>
Setting up the data cache
</summary>
public static void Setcache (String CacheKey, Object Objobject)
{
System.Web.Caching.Cache Objcache = Httpruntime.cache;
Objcache.insert (CacheKey, objobject);
}
<summary>
Setting up the data cache
</summary>
public static void Setcache (String CacheKey, Object Objobject, TimeSpan Timeout)
{
System.Web.Caching.Cache Objcache = Httpruntime.cache;
Objcache.insert (CacheKey, objobject, NULL, DateTime.MaxValue, Timeout, System.Web.Caching.CacheItemPriority.NotRemovable, NULL);
}
<summary>
Setting up the data cache
</summary>
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 Removeallcache (String CacheKey)
{
System.Web.Caching.Cache _cache = Httpruntime.cache;
_cache. Remove (CacheKey);
}
<summary>
Removing all Caches
</summary>
public static void Removeallcache ()
{
System.Web.Caching.Cache _cache = Httpruntime.cache;
IDictionaryEnumerator cacheenum = _cache. GetEnumerator ();
while (Cacheenum.movenext ())
{
_cache. Remove (CacheEnum.Key.ToString ());
}
}
}
}
[Cache] C # Operations Cache--cachehelper Cache Help class [copy link]