[Tool class] Cache helper Class

Source: Internet
Author: User

Write in front

In the statistical module of the project, the time spent in the query is too long, by optimizing the SQL statement or adding the cache to improve the speed of the query, I have a cache of auxiliary classes, easy to manipulate the data in the cache.

Cachehelper
1 usingSystem;2 usingSystem.Collections;3 usingSystem.Collections.Generic;4 usingSystem.Linq;5 usingSystem.Text;6 usingSystem.Threading.Tasks;7 usingsystem.web;8 usingSystem.Web.Caching;9 namespaceWebSite.Statistics.Core.UtilitiesTen { One     /// <summary> A     ///Cache Helper Classes -     /// </summary> -      Public Static classCachehelper the     { -         /// <summary> -         ///get cached data by key -         /// </summary> +         /// <param name= "CacheKey" ></param> -         /// <returns></returns> +          Public Static ObjectGetCache (stringCacheKey) A         { atCache Objcache =Httpruntime.cache; -             returnObjcache.get (CacheKey); -         } -         /// <summary> -         ///setting up the cache -         /// </summary> in         /// <param name= "CacheKey" >Cache Key</param> -         /// <param name= "ObjValue" >Cache Key</param> to          Public Static voidSetcache (stringCacheKey,ObjectObjValue) +         { -Cache cache =Httpruntime.cache; the Cache. Insert (CacheKey, objvalue); *         } $         /// <summary>Panax Notoginseng         ///setting up the cache -         /// </summary> the         /// <param name= "CacheKey" >Cache Key</param> +         /// <param name= "ObjValue" >the cached value</param> A         /// <param name= "Timeout" >Expiry Time</param> the          Public Static voidSetcache (stringCacheKey,ObjectObjValue, TimeSpan timeout) +         { -Cache cache =Httpruntime.cache; $Cache. Insert (CacheKey, ObjValue,NULL, DateTime.MaxValue, timeout, System.Web.Caching.CacheItemPriority.NotRemovable,NULL); $         } -         /// <summary> -         ///setting up the cache the         /// </summary> -         /// <param name= "CacheKey" >Cache Key</param>Wuyi         /// <param name= "ObjValue" >the cached value</param> the         /// <param name= "absoluteexpiration" >Absolute Expiration Time</param> -         /// <param name= "slidingexpiration" >Sliding Expiration Time</param> Wu          Public Static voidSetcache (stringCacheKey,ObjectObjValue, DateTime absoluteexpiration, TimeSpan slidingexpiration) -         { AboutCache cache =Httpruntime.cache; $Cache. Insert (CacheKey, ObjValue,NULL, absoluteexpiration, slidingexpiration); -         } -         /// <summary> -         ///removes the specified cache A         /// </summary> +         /// <param name= "CacheKey" ></param> the          Public Static voidRemoveCache (stringCacheKey) -         { $System.Web.Caching.Cache Cache =Httpruntime.cache; the Cache. Remove (CacheKey); the         } the         /// <summary> the         ///Removing all caches -         /// </summary> in          Public Static voidRemoveallcache () the         { theSystem.Web.Caching.Cache Cache =Httpruntime.cache; AboutIDictionaryEnumerator Cacheenum =Cache. GetEnumerator (); the              while(Cacheenum.movenext ()) the             { the Cache. Remove (CacheEnum.Key.ToString ()); +             } -         } the     }Bayi}
Summarize

Cache used a lot of places, the package of this class, but also a very basic thing, is a record, after the use of time, convenient to find.

[Tool class] Cache helper Class

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.