Copy codeThe Code is 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>
/// Clear the cache used
/// </Summary>
Public static void upload AchE ()
{
Foreach (string value in AllUseCacheKey)
{
HttpContext. Current. Cache. Remove (value );
}
AllUseCacheKey. Clear ();
}
}
}