通过web.config来自定义output caching缓存

我们服务器有开启缓存功能, 缓存功能可以减少您访问网站时候网站在服务器里面的编译时间, 大大加快您网站的访问速度, 如果您需要对您网站进行频繁更新的话, 您可以考虑暂时将缓存时间减少,或者暂时关闭缓存

请将下列代码放进web.config文件里面放在您网站的根目录;(注:以下remove extension 和add extension的参数要根据您网站的实际脚本填写,如果网站是php网站, 则用.php替代,如果是asp网站则用.asp替代,如果是asp.net网站,请用.aspx就可以了。)

1.在web.config里面设置缩小缓存的时间,请在web.config里面用下面的定义

      <system.webServer>
            <caching>
                <profiles>
                    <remove extension=".aspx" />
                    <add extension=".aspx" policy="CacheForTimePeriod" 

kernelCachePolicy="DontCache" duration="00:00:01" varyByQueryString="*" />
                </profiles>
            </caching>
      </system.webServer>

2. 如果要关闭某个页面的caching功能,请在web.config里面用下面的定义

    <configuration>
         <location path="showStockPrice.asp">
           <system.webServer>       
             <caching>
                <profiles>
                    <remove extension=".asp" />
                    <add extension=".asp" policy="DontCache" kernelCachePolicy="DontCache"/>
                </profiles>
            </caching>
           </system.webServer>
       </location>
    </configuration>

3. 如果要关闭整个程序的caching功能,请在web.config里面用下面的定义

<configuration>
           <system.webServer>       
             <caching>
                <profiles>
                    <remove extension=".asp" />
                    <add extension=".asp" policy="DontCache" kernelCachePolicy="DontCache"/>
                </profiles>
            </caching>
           </system.webServer>
    </configuration>

4. 如果要关闭根目录某个或某几个文件夹的caching功能,请在web.config里面用下面的定义

<location path="~/folderA,~/folderB">
    <system.webServer>
      <caching>
        <profiles>
          <remove extension=".asp" />
          <add extension=".asp" policy="DontCache" kernelCachePolicy="DontCache"/>
        </profiles>
      </caching>
    </system.webServer>
  </location>
</configuration>

扫描二维码关注公众号,回复: 4922899 查看本文章

您网站更新好之后, 建议您重新开启缓存,有利于加快您网站的访问速度。

IIS7服务器开启缓存功能有什么利弊?查

猜你喜欢

转载自www.cnblogs.com/namehou/p/10270466.html