public static Class Cachehelper
{
static Cache _cache = Httpruntime.cache;
<summary>
Get Cache
</summary>
<param name= "Key" ></param>
<returns></returns>
public static object Get (String key)
{
Return _cache. Get (key);
}
<summary>
Setting up the cache
</summary>
<param name= "Key" ></param>
<param name= "Value" ></param>
public static void Set (string key, Object value)
{
_cache. Insert (key, value);
}
<summary>
To set a valid cache for a specified time period
</summary>
<param name= "Key" ></param>
<param name= "Value" ></param>
<param name= "Expireseconds" > Cache time, units per second </param>
public static void Set (string key, object value, long Expireseconds)
{
_cache. Insert (key, value, NULL, DateTime.UtcNow.AddSeconds (expireseconds), TimeSpan.Zero);
}
<summary>
Clears the cached contents of the specified key
</summary>
<param name= "Key" ></param>
public static void Remove (String key)
{
_cache. Remove (key);
}
<summary>
Clears all cached content for a specified prefix for a keyword
</summary>
<param name= "Keyprefix" > Cache keyword prefix </param>
public static void Removecachebykeyprefix (String keyprefix)
{
System.Web.Caching.Cache _cache = Httpruntime.cache;
IDictionaryEnumerator cacheenum = _cache. GetEnumerator ();
ArrayList al = new ArrayList ();
while (Cacheenum.movenext ())
{
if (CacheEnum.Key.ToString (). StartsWith (Keyprefix))
{
Al. ADD (Cacheenum.key);
}
}
foreach (String key in AL)
{
_cache. Remove (key);
}
}
<summary>
Clear all cached content
</summary>
public static void Removeallcache ()
{
System.Web.Caching.Cache _cache = Httpruntime.cache;
IDictionaryEnumerator cacheenum = _cache. GetEnumerator ();
ArrayList al = new ArrayList ();
while (Cacheenum.movenext ())
{
Al. ADD (Cacheenum.key);
}
foreach (String key in AL)
{
_cache. Remove (key);
}
}
}
Common tool classes 8-cache classes