zoukankan      html  css  js  c++  java
  • asp.net 缓存

    1.Output Caching

    With output caching, the final rendered HTML of the page is cached. When the same page is requested again, the control objects are not created, the page life cycle doesn’t start, and none of your code executes. Instead, the cached HTML is served.

    You can cache an ASP.NET page in two ways. The most common approach is to insert the OutputCache directive at the top of your .aspx file,just below the Page directive, as shown here:

    <%@ OutputCache Duration="20" VaryByParam="None" %>

    The Duration attribute instructs ASP.NET to cache the page for 20 seconds.

    OutputCache 指令实际上是asp.net向响应头中输出了三个响应头:

    image

    You can set the VaryByParam attribute to * to indicate that the page uses the query  string and to instruct ASP.NET to cache separate copies of the page for different query string arguments:

    <%@ OutputCache Duration="20" VaryByParam="*" %>

    Now when you request the page with additional query string information, ASP.NET will examine the query string. If the string matches a previous request  and a cached copy of that page exists, it will be reused. Otherwise, a new copy of the p age will be created and cached separately.

    2.Caching with Specific Query String Parameters

    Setting VaryByParam to the wildcard asterisk (*) is unnecessarily vague. It’s usually better to specifically identify an important query string  variable by name. Here’s an example:

    <%@ OutputCache Duration="20" VaryByParam="ProductID" %>

    In this case, ASP.NET will examine the query string, looking for the ProductID parameter. Requests with different ProductID parameters  will be cached separately, but all other parameters will be ignored.

    You can specify several parameters as long as you separate them with semicolons:

    <%@ OutputCache Duration="20" VaryByParam="ProductID;CurrencyType" %>

    In this case, ASP.NET will cache separate versions, provided the query string differs by ProductID or CurrencyType.

  • 相关阅读:
    [转]移动端实现垂直居中的几种方法
    MySQL常见的两种存储引擎:MyISAM与InnoDB的爱恨情仇
    关于分布式计算的一些概念
    一份最中肯的Java学习路线+资源分享(拒绝傻逼式分享)
    Java多线程学习(八)线程池与Executor 框架
    深入理解工厂模式
    深入理解单例模式
    Java NIO 之 Buffer(缓冲区)
    Java NIO 概览
    分布式系统的经典基础理论
  • 原文地址:https://www.cnblogs.com/weekend001/p/3662688.html
Copyright © 2011-2022 走看看