ASP.NET 2.0 缓存技术
<script src="/googlead/ad336280-4.js" type="text/javascript"></script> <script type="text/javascript"> </script> <script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"> </script>ASP.NET2.0 缓存(Cache)技术介绍_立华软件园_技术文档->Web开发->ASP.Net
NET 2.0提供了一些新的用于提升程序性能的技术特性,其中,缓存技术是非常重要的一个 特性,它提供了一种非常好的本地数据缓存机制,可以非常容易的定制属于数据缓从,从而 有效的提高数据访问的性能。 ASP.NET 2.0提供了一些新的用于提升程序性能的技术
http://www.lihuasoft.net/article/show.php?id=3281
ASP.NET 2.0的缓存技术简介- ASP.NET - 网海拾贝| 电脑资讯资源站
电脑资讯,电脑快报,it资讯,网站建设资讯,教程基地,编程开发ASP.NETASP.NET 2.0的缓存 技术简介.
http://www.xland.com.cn/read.php?wid=12353
一、SQL Cache 通过配置数据库连接池,只有当数据库数据被改变的时候,缓存才会改变:
注册连接池 命令:c:dir aspnet_regsql.exe 专门注册连接池的工具 在sql数据库的数据库改变了,才改变缓存。
参数: _s 制定注册的服务器、 _e 说明是windows授权模式、 _u和 _p 说明是sql数据库的授权模式、
_d 指定数据库的名字、_ed 说明缓存生效。
事例1、 aspnet_regsql.exe _s sqlexpress _e _d pubs _ed 注册到pubs库
事例2. aspnet_regsql.exe _s sqlexpress _e _d pubs _et _1 authors 注册到pubs库的表
<%@ outputcache duuation=999999 sqldependency=pubs;authors varybyparam=none%>在页面中加入
注意:注册的库不要太多,主要的经常用的注册 最好在两个库以内,也不需要每个库中的的表都注册
二、Output Caching
1、 <%@ OutputCache Duration=60 VaryByParam=none %> 页面的前面加这句就可以
2、 Duration 缓存的间隔时间 VaryByParam request是否有返回参数改变
3、 根据参数缓存 <%@ OutputCache Duration=60 VaryByParam=state %>
<SelectParameters>
<asp:QueryStringParameter Name=state QueryStringField=state DefaultValue=CA />
</SelectParameters> 这个是在dataview 中设置的
4、缓存到硬盘 <%@ OutputCache Duration=3600 VaryByParam=name DiskCacheable=true %>
DiskCacheable 是设置缓存到硬盘
5、回调缓存 一个页面一部分需要缓存而其他的不需要缓存,实现动态缓存 6、用户控件 的参数缓存
< SelectParameters >
< asp:ControlParameter ControlID =pickstate DefaultValue =CA Name =state PropertyName =SelectedValue />
</ SelectParameters >
API缓存,比较复杂,一般不采用这中方法
API回调缓存
Shared Function GetCurrentDate(context As HttpContext) As String
return DateTime.Now.ToString()
End Function
</ script >
< b >
Real Time: <% Response.WriteSubstitution(New HttpResponseSubstitutionCallback(AddressOf GetCurrentDate)) %>
Sub Page_Load(ByVal Src As Object, ByVal E As EventArgs)
Dim Source As DataView
try to retrieve item from cache
if its not there, add it
Source = Cache(MyDataSet)
If Source Is Nothing Then
Dim MyConnection As SqlConnection
Dim MyCommand As SqlDataAdapter
MyConnection = New SqlConnection(ConfigurationManager.ConnectionStrings(pubsConnectionString).ConnectionString)
MyCommand = New SqlDataAdapter(select * from Authors, MyConnection)
Dim ds As New DataSet
MyCommand.Fill(ds, Authors)
Source = New DataView(ds.Tables(Authors))
Cache(MyDataSet) = Source
CacheMsg.Text = Dataset created explicitly
Else
CacheMsg.Text = Dataset retrieved from cache
End If
MyGrid.DataSource = Source
MyGrid.DataBind()
End Sub
</ script >
这种数据缓存的效率比较高,可以缓存很大的数据量,可以同时缓存到内存和硬盘
< outputCache >
< diskCache enabled =true maxSizePerApp =2 /> 设置在硬盘中缓存 单位是兆
</ outputCache >
< outputCacheSettings >
< outputCacheProfiles >
< add name =CacheFor60Seconds duration =60 />
</ outputCacheProfiles >
</ outputCacheSettings >
<!--
<sqlCacheDependency enabled=true pollTime=1000 >
<databases>
<add name=PubsDB connectionStringName=pubsConnectionString />
</databases>
</sqlCacheDependency>
-->
</ caching >
<script runat=server>
Shared Function GetCurrentDate(ByVal context As HttpContext) As String
Return Now.ToString()
End Function
</script>
<p>
<b> Real Time:
<asp:Substitution ID=Substitution1 runat=server MethodName=GetCurrentDate />
</b>
</p>