[Cache] C # Operations Cache--cachehelper Cache Help class [copy link]

Source: Internet
Author: User


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]

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.