Cache, Cache

.NET 的功能强大,可能资源消耗大,问题之一就是编译慢和数据臃肿。所以有了ASPX页面的各种缓冲功能(1.0,1.1已有,这里不讨论),2.0还提供了数据库的缓冲来解决数据臃肿的问题。特记下下面的步骤,以备查询:

1、在应用程序的配置文件中设置好参数,例子如下:

<configuration>
  <connectionStrings>
    <add name="pubsConnectionString" connectionString="Server=localhost;Database=Pubs;integrated  
  security=true" />
  </connectionStrings>
  <system.web>
    <caching>
       <sqlCacheDependency enabled="true">
   <databases>
     <add name="Pubs"
        connectionStringName="pubsConnectionString"
        pollTime="60000" />
   </databases>
</sqlCacheDependency>
    </caching>
  </system.web>
</configuration>

2、然后在SQL Server中注册通知服务,

aspnet_regsql -S localhost -E -d pubs -ed

这个步骤只是针对SQL 2000的,SQL 2005 不用注册。

3、登记需要通知的表,比如 authors

aspnet_regsql -S localhost -E -d pubs -t authors -et

4、最后,在数据源说明缓存关系:

<asp:objectdatasource EnableCaching="true"
    SqlCacheDependency="Pubs:authors"
    CacheDuration="10000" runat="server" id="authorsSource"
    typename="AuthorsBiz" selectmethod="GetAuthors">
  </asp:objectdatasource>

有三个相关的参数,EnableCaching, SqlCacheDependency & CacheDuration

这些例子是从15 seconds上的一篇文章上摘抄的,完整的文章在以下的地址:

N-Tier Web Applications using ASP.NET 2.0 and SQL Server 2005
posted @ 2005-08-31 01:38  dawave  阅读(523)  评论(0编辑  收藏  举报