OutputCache
Duration 缓存间隔时间,单位秒
VaryByParam 是否通过提交不同参数而缓存页面
DiskCacheable ="true" :硬盘缓存,当数据量比较大的时候使用;例大容量的dataset
dataCaching
sql Caching
只有当数据库数据改变时,缓存才改变
配置SQL连接池
文件 aspnet_regsql.exe
文件位置\windows\microsoft.net\framework\你的.net framework的版本号
参数
-s指定注册的服务器
-e使用windows授权模式
-d指定数据库名字
-ed缓存生效
aspnet_regsql.exe -s "sqlexpress" -e -d "pubs" -ed 注册库
aspnet_regsql.exe -s "sqlexpress" -e -d "pubs" -et -t "authors"
web.config配置缓存
回调缓存 偏向API和HTML上下文(未测试)
<%@ OutputCache Duration="60" VaryByParam="none" %>
VaryByParam 是否通过提交不同参数而缓存页面
DiskCacheable ="true" :硬盘缓存,当数据量比较大的时候使用;例大容量的dataset
dataCaching
Dim Source As DataView
' try to retrieve item from cache
' if it's not there, add it
Source = Cache("MyDataSet")
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"
' try to retrieve item from cache
' if it's not there, add it
Source = Cache("MyDataSet")
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"
sql Caching
<%@ OutputCache Duration="999999" SqlDependency="pubs.authors" VaryByParam="none" %>
监视有限的库和表,注册1,2个较合适只有当数据库数据改变时,缓存才改变
配置SQL连接池
文件 aspnet_regsql.exe
文件位置\windows\microsoft.net\framework\你的.net framework的版本号
参数
-s指定注册的服务器
-e使用windows授权模式
-d指定数据库名字
-ed缓存生效
aspnet_regsql.exe -s "sqlexpress" -e -d "pubs" -ed 注册库
aspnet_regsql.exe -s "sqlexpress" -e -d "pubs" -et -t "authors"
web.config配置缓存
<caching>
<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>
<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>
回调缓存 偏向API和HTML上下文(未测试)
<asp:Substitution ID="Substitution1" runat="server" MethodName="GetCurrentDate" />
.cs/.vb
page Fragment Caching(未测试)
在页面中,通过指定返回参数,决定控件被缓存的部分,使用VaryByParam语句指定控件根据参数改变而改变
Shared Function GetCurrentDate(ByVal context As HttpContext) As String
Return Now.ToString()
End Function
Return Now.ToString()
End Function
page Fragment Caching(未测试)
在页面中,通过指定返回参数,决定控件被缓存的部分,使用VaryByParam语句指定控件根据参数改变而改变
浙公网安备 33010602011771号