Copy Code code as follows:
Using System.Collections.Generic;
Using System.Web;
Using System;
Namespace DataAccess
{
<summary>
Cache Control class
</summary>
public class CacheControl
{
public static list<string> Allusecachekey = new list<string> ();
<summary>
Add cache
</summary>
<param name= "Key" ></param>
<param name= "Value" ></param>
<param name= "absoluteexpiration" ></param>
public static void Addcache (string key, Object value, DateTime absoluteexpiration)
{
if (! Allusecachekey.contains (Key))
{
Allusecachekey.add (key);
}
HTTPCONTEXT.CURRENT.CACHE.ADD (key, value, NULL, absoluteexpiration, TimeSpan.Zero, System.Web.Caching.CacheItemPriority.Normal, NULL);
}
<summary>
Remove Cache
</summary>
<param name= "Key" ></param>
public static void RemoveCache (String key)
{
if (Allusecachekey.contains (key))
{
Allusecachekey.remove (key);
}
HttpContext.Current.Cache.Remove (key);
}
<summary>
Emptying the Used cache
</summary>
public static void ClearCache ()
{
foreach (string value in Allusecachekey)
{
HttpContext.Current.Cache.Remove (value);
}
Allusecachekey.clear ();
}
}
}