1.Output Caching
    一旦Output Caching被定制过,这个网页就会在第一次被访问的时候生成Cahce,直到请求过期为止。
    <%@ OutputCache Duration="60" VaryByParam="none" %>
    Duration表示缓存的间隔时间;VarByParam表示是否通过request接受的参数改变缓存.

    可以根据不同的参数来缓存页面,见Demo中的VaryByPostBack.aspx
    <%@ OutputCache Duration="60" VaryByParam="state" %>

    硬盘Output Cache(默认是打开的)
    <%@ OutputCache Duration="3600" VaryByParam="name" DiskCacheable="true" %>
 
 <system.web>
    <caching>
      <outputCache>
        <diskCache Enabled="true" maxSizePerApp="2"/>
      </outputCache>
    </caching>
 </system.web>
 
    回调缓存
    通过设置回调缓存机制,可以针对每个讲求在页面中插入动态的部分,以弥补单独使用静态缓存的不足.
    <script runat="server">
    Shared Function GetCurrentDate(ByVal context As HttpContext) As String
        Return Now.ToString()
    End Function
    </script>
    <asp:Substitution ID="Substitution1" runat="server" MethodName="GetCurrentDate" />


    2.Fragment Caching(页面碎片缓存)
 页面上部分内容根据请求动态更新,大部分能容被缓存。(如果多个控件需要缓存,可做成一个用户控件)
 <%@ OutputCache Duration="60" VaryByControl="WebUserControl1" %>
 
    3.Data Caching
    DataSet ds=new DataSet();
    ds = Cache["restaurant"];
    if (ds == null)
    {
        ds = resDataSet;
        Cache["restaurant"] = ds;
    }

 

    4.SQL Cache
    配置数据库连接池
    C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727>aspnet_regsql.exe
    运行 asp.net sql Server配置向导
    Aspnet_regsql.exe –S “\DBNAME” –E –d “pubs” –ed
    -E windows 授权
    –ed 为enabled
    Aspnet_regsql.exe –S “\DBNAME” –E –D “pubs” –et –t “authors”
    当 pubs.authors 改变时改变缓存
    <%@ OutputCache Duration="9999999" VaryByParam="none" SqlDependency="pubs.authors" %>

    缓存配置
         <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>

 

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

posted on 2008-03-19 16:26  菲奥内  阅读(215)  评论(0)    收藏  举报