ASP.NET緩存處理類實(shí)例
本文實(shí)例講述了ASP.NET緩存處理類。分享給大家供大家參考。具體如下:
ASP.NET 緩存處理類。
用法:
Just copy this code into a new class file (.cs) and add it to your ASP .NET website. One thing to keep in mind is that data stored in ASP .NET Cache can be accessible across all sessions. So when creating a cacheID for the object to be stored, it must be unique (or it could be overwritten). I usually store the unique cacheID in the session and then use that to referrence the cacheID. (e.g. CacheHandler.Write(Session["MyCacheData"], myData);)
具體代碼如下:
using System; using System.Collections.Generic; using System.Web.Caching; using System.Web; /// <summary> /// This class reads/writes to ASP .NET server cache. For the sake of /// simplicity, the class writes objects to cache with no expirateion. /// Use the Remove() function to programmatically remove objects stored /// from the server cache. This class was created as an alternative to /// storing large objects in the session. /// </summary> public class CacheHandler { public static bool Write(string cacheID, object data) { if (HttpContext.Current == null) return false; if (cacheID == null || cacheID.Equals("")) return false; HttpRuntime.Cache.Insert( cacheID, data, null, Cache.NoAbsoluteExpiration, Cache.NoSlidingExpiration, CacheItemPriority.NotRemovable, null ); return true; } public static object Read(string cacheID) { if (HttpContext.Current == null) return null; return HttpRuntime.Cache.Get(cacheID); } public static void Remove(string cacheID) { if (HttpContext.Current == null ) return; if (cacheID == null || cacheID.Equals("")) return; HttpRuntime.Cache.Remove(cacheID); } }
希望本文所述對(duì)大家的asp.net程序設(shè)計(jì)有所幫助。
相關(guān)文章
.Net Core微信服務(wù)商二次進(jìn)件的開(kāi)發(fā)
這篇文章主要介紹了.Net Core微信服務(wù)商二次進(jìn)件的開(kāi)發(fā),包括服務(wù)商證書(shū)獲取方法及查詢進(jìn)件狀態(tài)的詳細(xì)代碼,本文給大家介紹的非常詳細(xì),需要的朋友可以參考下2021-10-10ASP.NET頁(yè)面優(yōu)化 性能提升8倍的方法
今天與大家分享:一種優(yōu)化頁(yè)面執(zhí)行速度的方法。采用這個(gè)方法,可以使用頁(yè)面的執(zhí)行速度獲得【8倍】的提升效果2012-03-03asp.net服務(wù)器上幾種常見(jiàn)異常的解決方案.
由于以前就業(yè)時(shí)算是公司里對(duì)服務(wù)器上各種硬件和配置原理較為了解. 一直負(fù)責(zé)公司服務(wù)器日常管理.也算是半路出家. 當(dāng)然日常工作中前前后后也遇到不少大大小小的問(wèn)題(硬件/服務(wù)器日常配置 數(shù)據(jù)中心合并方案等等). 有1些常見(jiàn)的異常. 總結(jié)一些基本快速的處理方法.2009-11-11Linq to SQL Delete時(shí)遇到問(wèn)題的解決方法
在Linq to SQL中要?jiǎng)h除一行記錄,官方的例子教我這樣做2008-03-03Asp.Net 網(wǎng)站優(yōu)化系列之?dāng)?shù)據(jù)庫(kù)優(yōu)化分字訣上 分庫(kù)
當(dāng)我們的數(shù)據(jù)量很小的時(shí)候,我們會(huì)把用戶表,博客表,論壇表,閃存表等等都砸在一個(gè)庫(kù)里,我們的業(yè)務(wù)增長(zhǎng)的很好,在不久之后我們盡力的優(yōu)化了查詢,但是效果依然不佳,這時(shí)候用分字訣的時(shí)機(jī)到了。2010-06-06SQL為查詢的結(jié)果加上序號(hào)(ROW_NUMBER) 合并多個(gè)查詢結(jié)果
SQL為查詢的結(jié)果加上序號(hào)(ROW_NUMBER) 合并多個(gè)查詢結(jié)果2010-03-03