ASP.NETキャッシュOutputCacheとResponse.CacheのC#バックグラウンド設定

3269 ワード

 、ASPX    
, aspx <%@ OutputCache Duration="60" VaryByParam="none" %>
  , ASP.NET 、 , 。
  。 1 1 、 100 。
、outpuCache
Duration
: ,
VaryByParam: ,
  VaryByParam=none , ;
  VaryByParam="*" , VaryByParam="*", “*” 。
  VaryByParam="id" ?id=2、?id=3 , , VaryByParam="id"
  DiskCacheable="true|false" 

注意:Buffer=true;次の設定が有効になります.ページのデフォルトはtrueです.
三、以下はコード例の@OutputCache命令と等価なプログラミングコードである.
  • 出力キャッシュに指定した期間宣言メソッドを格納するには、次の手順に従います.
    <%@ OutputCache Duration="60" VaryByParam="None" %>

    プログラミングの方法:
    Response.Cache.SetExpires(DateTime.Now.AddSeconds(60));
    
    Response.Cache.SetCacheability(HttpCacheability.Public);

  • 要求を発行したブラウザクライアントに出力キャッシュ宣言メソッドを格納する.
    <%@ OutputCache Duration="60" Location="Client" VaryByParam="None" %>

    プログラミングの方法:
    Response.Cache.SetExpires(DateTime.Now.AddSeconds(60));
    
    Response.Cache.SetCacheability(HttpCacheability.Private);

  • HTTP 1.1でキャッシュをサポートするデバイスは、プロキシサーバおよび要求を発行するクライアントに出力キャッシュ宣言メソッドを格納することを含む.
    <%@ OutputCache Duration="60" Location="Downstream" VaryByParam="None" %>

    プログラミングの方法:
    Response.Cache.SetExpires(DateTime.Now.AddSeconds(60));
    
    Response.Cache.SetCacheability(HttpCacheability.Public);
    
    Response.Cache.SetNoServerCaching();

  • Webサーバに出力キャッシュを格納する宣言メソッド:
    <%@ OutputCache Duration="60" Location="Server" VaryByParam="None" %>

    プログラミングの方法:
    TimeSpan freshness = new TimeSpan(0,0,0,60); 
    
    DateTime now = DateTime.Now; 
    
    Response.Cache.SetExpires(now.Add(freshness)); 
    
    Response.Cache.SetMaxAge(freshness); 
    
    Response.Cache.SetCacheability(HttpCacheability.Server); 
    
    Response.Cache.SetValidUntilExpires(true);

  • キャッシュが到着すると、異なる都市の各HTTP要求の出力を使用します.宣言方法:
    <%@ OutputCache duration="60" varybyparam="City" %>

    プログラミングの方法:
    Response.Cache.SetExpires(DateTime.Now.AddSeconds(60));
    
    Response.Cache.SetCacheability(HttpCacheability.Public);
    
    Response.Cache.VaryByParams["City"] = true;

    HttpResponse.RemoveOutputCacheItem("/index.aspx");