zoukankan      html  css  js  c++  java
  • Using Output Cache

    Using Output Cache

     

    Output page caching is an ASP.NET feature that increases the performance of your web application by caching the HTML content generated from dynamic pages or controls. In other words, a page or user control that has output caching enabled is only executed the first time it is requested. On subsequent requests, the page or control is served directly from the cache, instead of being executed again.

     

    The drawback with output caching is that if the information in the database changes in the meanwhile, your page will display outdated information. Also, enabling output caching, although it saves server-processing power, consumes server memory, and should be used with caution.

     

    You can enable output page caching for a Web Form or Web User Control using the OutputCache page directive, which has a number of optional parameters:

    <%@ OutputCache

    Duration="#ofseconds"

    Location="Any | Client | Downstream | Server | None"

    Shared="True | False"

    VaryByControl="controlname"

    VaryByCustom="browser | customstring"

    VaryByHeader="headers"

    VaryByParam="parametername" %>

     

    Explanation:

    Shared: Applies only to user controls, and specifies whether the output of the user

    control should be cached once for all the pages that include the control, or if multiple

    versions of the control should be cached for each page that contains it.

     

    VaryByParam: Varies the output cache based on the values of the parameters passed to

    the server, which include the query string parameters.

     

    For example:

    <%@ OutputCache Duration="1000"

    VaryByParam="DepartmentIndex;CategoryIndex;Search;AllWords;PageNumber;

    ProductsOnPage" %>

     

    Although implementing output page caching saves the database, it occupies web server memory.

     

    For this reason, I recommend that implementing output caching for some static web user controls, such as Page Header, Page Footer, and so on.

     

    Note: The above content is excerpted from ASP.NET 2.0 ecommerce in C# 2005 From Novice to Professional – Apress.

     

     

  • 相关阅读:
    面对祖传屎山代码应该采用的5个正确姿势
    一行代码卖出570美元, 天价代码的内幕
    漫画 | 悲催的中国式软件开发
    看看我每天的工作,你们这些程序员都是“辣鸡”!
    漫画 | 浏览器一个比一个“无耻”
    程序员应该造的五大轮子
    我所尊敬的三位女程序员
    重磅!七国首脑会议决定制裁Go语言!
    漫画 | C语言哭了,过年回家,只有我还没对象
    漫画 | CPU战争40年,真正的王者终于现身!
  • 原文地址:https://www.cnblogs.com/rickie/p/426662.html
Copyright © 2011-2022 走看看