技术开发 频道

ASP.NET2.0揭秘读书笔记:页面输出缓存

  创建页面输出缓存配置
      
  通过在Web配置文件中配置页面输出缓存,从而将这些配置应用于多个页面。可以创建一个缓存配置(Cache Profile),将使网站的缓存更容易管理。

<system.web>
    
<caching>
  
      
<outputCacheSettings>
        
<outputCacheProfiles>
          
<add name="Cache1Hour" duration="3600" varyByParam="none" />
        
</outputCacheProfiles>
      
</outputCacheSettings>
    
</caching>
  
</system.web>

  下面代码使用了Cache1Hour配置。该配置设置于<% OutputCache%>指令的CacheProfile属性。

<%@ Page Language="C#" %>
<%@ OutputCache CacheProfile="Cache1Hour" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    
<title>Output Cache Profile</title>
</head>
<body>
    
<form id="form1" runat="server">
    
<div>
    
<%= DateTime.Now.ToString("T") %>
    
    
</div>
    
</form>
</body>
</html>

  可以给缓存配置设置和独立页面的<%OutputCache%>指令一样的属性。

0
相关文章