Using system;
Using system. Collections. Generic;
Using system. LINQ;
Using system. text;
Using system. collections;
Using system. Web;
Namespace Utility
{
Public class datacache
{
/// <Summary>
/// Obtain the cache value of the specified cachekey of the current application
/// </Summary>
/// <Param name = "cachekey"> </param>
/// <Returns> </returns>
Public static object getcache (string cachekey)
{
System. Web. caching. cache objcache = httpruntime. cache;
Return objcache [cachekey];
}
/// <Summary>
/// Set the cache value of the specified cachekey for the current application
/// </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>
/// Set the cache value of the specified cachekey for the current application
/// </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>
/// Clear the single-key Cache
/// </Summary>
/// <Param name = "key"> </param>
Public static void removeonecache (string cachekey)
{
System. Web. caching. cache objcache = httpruntime. cache;
Objcache. Remove (cachekey );
}
/// <Summary>
/// Clear all caches
/// </Summary>
Public static void removeallcache ()
{
System. Web. caching. cache _ cache = httpruntime. cache;
Idictionaryenumerator cacheenum = _ cache. getenumerator ();
If (_ cache. Count> 0)
{
Arraylist Al = new arraylist ();
While (cacheenum. movenext ())
{
Al. Add (cacheenum. Key );
}
Foreach (string key in Al)
{
_ Cache. Remove (key );
}
}
}
/// <Summary>
/// Return all existing caches in the form of a list
/// </Summary>
/// <Returns> </returns>
Public static arraylist showallcache ()
{
Arraylist Al = new arraylist ();
System. Web. caching. cache _ cache = httpruntime. cache;
If (_ cache. Count> 0)
{
Idictionaryenumerator cacheenum = _ cache. getenumerator ();
While (cacheenum. movenext ())
{
Al. Add (cacheenum. Key );
}
}
Return al;
}
}
}