您的位置:知识库 » .NET技术

ASP.NET 2.0缓存技术探讨

作者: 棋木空间  来源: 博客园  发布时间: 2009-05-12 10:46  阅读: 4982 次  推荐: 0   原文链接   [收藏]  
摘要:本文介绍通过缓存来提高网页的执行效率,包括ASP.NET Output Caching、Page Fragment Caching等内容。
[1] ASP.NET Output Caching
[2] Page Fragment Caching
[3] Data Caching
[4] SQL Cache

   4. SQL Cache

  前面的例子中,我们使用的是缓存技术,一旦时间到,无论服务器端的数据是否改变都会释放缓存,下面介绍的例子,通过配置数据库连接池,只有当数据库数据被改变的时候,缓存才会改变。

  示例:配置连接池示例

  开一个DOS窗口->找到aspnet_regsql.exe工具(常用参数:-s指定我们注册的服务器-E使用Windows授权模式-D指定数据库DataBase名字-ED缓存生效)->

aspnet_regsql.exe –s “.SQLExPress” –E –d “pubs” –ed

aspnet_regsql.exe –s “.SQLExPress” –E –d “pubs” –et –t  “authors”

<%@ OutputCache Duration = “999999” SqlDependency = “Pubs:Authors” VaryByParam = “none”%>

5.       Cache Configuration

可以通过在webconfig里配置不同的缓存描述,在页面中调用该描述来减少重复定义缓存描述的工作量。

示例:缓存描述定义示例:

<configuration>
<appSettings/>
<system.web>
<caching>
<outputCache>
<diskCache enabled="true" maxSizePerApp="2"(2M) />
</outputCache>
<outputCacheSettings>
<outputCacheProfiles>
<add name="CacheFor60Seconds" duration="60" />
</outputCacheProfiles>
</outputCacheSettings>
<!--
<sqlCacheDependency enabled="true" pollTime="1000"
<databases>
<add name="PubsDB" connectionStringName="pubsConnectionString" />
</databases>
</sqlCacheDependency>
-->
</caching>
</system.web>
</configuration>
0
0
标签:ASP.NET 缓存

.NET技术热门文章

    .NET技术最新文章

      最新新闻

        热门新闻