日期:2014-05-18  浏览次数:20458 次

关于asp.net 中的缓存使用
请问asp.net中的缓存在什么时候用到》具体在什么情况下》谢谢

------解决方案--------------------
提高访问速度的时候用到。
------解决方案--------------------
缓存是一种无需大量时间和分析就可以获得“足够良好的”性能的方法。这里再次强调,内存现在非常便宜,因此,如果您能通过将输出缓存 30 秒,而不是花上一整天甚至一周的时间尝试优化代码或数据库就可以获得所需的性能,您肯定会选择缓存解决方案(假设可以接受 30 秒的旧数据)。缓存正是那些利用 20% 付出获得 80% 回报的特性之一,因此,要提高性能,应该首先想到缓存。不过,如果设计很糟糕,最终却有可能带来不良的后果,因此,您当然也应该尽量正确地设计应用程序。但如果您只是需要立即获得足够高的性能,缓存就是您的最佳选择,您可以在以后有时间的时候再尽快重新设计应用程序。


http://www.microsoft.com/china/MSDN/library/WebServices/ASP.NET/ASP.NETCaching-TechniquesandBestPractiCEs.mspx?mfr=true

http://www.weiw.com/article/list.asp?id=819
------解决方案--------------------
up
------解决方案--------------------
缓存,古来有之的概念

就是,拿到了数据,使用之后不丢弃,临时保存起来,通常是内存中,下次需要的时候,直接取内存数据,对于数据库数据,就不必再次访问数据库,地球人都知道,访问内存,必访问 IO 速度快几个数量级
------解决方案--------------------
如果有些数据不是经常要更新.可能很久才变的,访问量又大,这时用缓存可大大增加性能.
------解决方案--------------------
你不断的点 Button 看页面效果

// .aspx
<asp:button onclick=CacheBtn_Click ...

// .aspx.cs
// This is a simple page that demonstrates how to place a value
// in the cache from a page, and one way to retrieve the value.
// Declare two constants, myInt1 and myInt2 and set their values
// and declare a string variable, myValue.
const int myInt1 = 35;
const int myInt2 = 77;
string myValue;

// When the page is loaded, the sum of the constants
// is placed in the cache and assigned a key, key1.
void Page_Load(Object sender, EventArgs arg) {
Cache[ "key1 "] = myInt1 + myInt2;

}

// When a user clicks a button, the sum associated
// with key1 is retrieved from the Cache using the
// Cache.Get method. It is converted to a string
// and displayed in a Label Web server control.
void CacheBtn_Click(object sender, EventArgs e) {
if (Cache[ "key1 "] == null) {
myLabel.Text = "That object is not cached. ";
}
else {
myValue = Cache.Get( "key1 ").ToString();
myLabel.Text = myValue;
}
}
------解决方案--------------------
楼主注意了:缓存也有不好的时候,比如:刚从数据库中获取的数据放在缓存中,但是需要修改数据,这个时候要注意缓存里的数据了,修改完毕,提交保存按钮以后,有可能数据会不更新,原因在于缓存中保存的是原来的数据。还有如果有两个以上的人同时在操作同样的操作,有可能数据会混乱,请楼主注意。
------解决方案--------------------
1\缓存的数据最好实时性不高;
2\访问页面的量很大;
3\最好每个人访问的数据是一样的;不会因为每个人的用户不同产生不同的数据;
4\缓存页面的选择是要经过对网站页面的分析以后才能确定的;