« Previous Next »

Thread: IIS7 Caching Difficulties

Last post 08-10-2009 12:27 PM by ShadwChsr. 7 replies.

Average Rating Rate It (5)

RSS

Page 1 of 1 (8 items)

Sort Posts:

  • 08-05-2009, 7:06 PM

    IIS7 Caching Difficulties

    I've been trying to configure server side caching for a WCF service hosted on IIS7, but I've been encountering some strange issues that appear to be either design flaws or bugs in IIS7's caching framework.

    * The documentation for "duration" on a caching profile states that it's configured as "seconds", even though it's a timespan instance. If it was a TimeSpan, specifying duration="5" would mean 5 days, not 5 seconds. The documentation appears to be wrong. http://msdn.microsoft.com/en-us/library/ms691315.aspx

    * The documentation states that the "location" value's default is "Any". However, when I view the HTTP response IIS7 has set cache-control to "no-cache". The documentation appears to be wrong. http://msdn.microsoft.com/en-us/library/ms691315.aspx

    * There is no way to configure server side caching without also setting client-side headers! This is an extremely aggrivating frustration and I might be a design oversight. For example, setting <add extension=".svc" policy="CacheForTimePeriod" duration="12:00:00" /> results in a "Cache-Control: no-cache" header, which is not what I want. There doesn't appear to be any way to configure server side caching without affecting the cache-control header. For example, I may want to configure server side caching while leaving the client at it's "default" setting.

    * The documentation for "varyByQueryString" is confusing. Does that mean that differing querystrings are treated as the same response by kernel mode caching? Shouldn't the default be to treat each canonical URL (including querystrings) as a unique response for caching, even in the kernel? It seems as though the correct behavior is the opposite - that all querystrings are "non-varied" unless specified otherwise. They are parameters that affect the response, after all. For example, product.aspx?product=1 is NOT the same as product.aspx?product=2.

    Take an ASPX site as an example. How am I supposed to configure varyByQueryString? If I have 100 .ASPX pages and want to cache them, I would then create a "caching profile" for the .ASPX extension in the web.config. Each of those 100 ASPX files may have differnet querystrings - can you imagine having to configure hundreds of different querystring parameters in a single varyByQueryString attribute? What a nightmare.

    * My application sets it's own "Cache-Control" header of "public,max-age=1209600". If I also configure IIS 7 server side caching, the returned response header appears as: "Cache-Control: no-cache,public,max-age=1209600". Definitely a bug! Again, IIS is mucking with my headers and not even doing it correctly.

    * IIS 7 doesn't "transparently cache" based on what the application sets in it's cache-control header. For example, my application itself could determine what needs to be cached on a url-by-url basis. I'm already setting "Cache-Control: Public" as a response header. IIS7's server side cache is "upstream" from my generated response, so if caching was enabled it seems to me it should just gracefully cache as the default behavior. For example, I might be programming an ASP.NET MVC website - there are no extensions to configure since it uses application routing. That makes using IIS7 caching next to impossible.

    Help! I really need server side caching for performance, but I'm not sure how to make it behave properly and stop messing with my client side headers.

  • 08-05-2009, 9:59 PM In reply to

    • lextm
    • Top 10 Contributor
    • Joined on 10-22-2008, 4:18 AM
    • Shanghai, PRC
    • Posts 1,417

    Re: IIS7 Caching Difficulties

    Hope that you have read the troubleshooting tips mentioned below to dig further. http://learn.iis.net/page.aspx/154/iis-70-output-caching/ Besides, for ASP.NET MVC or WCF, your best resources are our ASP.NET/MSDN forums. http://forums.asp.net/1146.aspx http://social.msdn.microsoft.com/forums/en-US/wcf/threads/
    Lex Li
    Support Engineer at Microsoft
    ---------------------------
    This posting is provided "AS IS" with no warranties, and confers no rights.
  • 08-06-2009, 12:00 PM In reply to

    Re: IIS7 Caching Difficulties

    I've been through the troubleshooting steps and documentation. I'll take another look... something is definitely strange - might be a defect in IIS 7.5 RC, not IIS 7

  • 08-06-2009, 12:32 PM In reply to

    • anilr
    • Top 10 Contributor
    • Joined on 05-23-2006, 6:13 PM
    • Redmond, WA
    • Posts 2,343

    Re: IIS7 Caching Difficulties

    duration is a timeSpan and follows the standard timeSpan parsing rules, so 5 is 5secs, and 5:00 is 5mins.

    default for location is Server, you can find config schema (including defaults) in %windir%\system32\inetsrv\config\iis_schema.xml - I will try to get the documentation corrected

    Unfortunately, configuring this feature will always set cache-control header (either public or private or no-cache), but you can override it in your application code by replacing the header rather than appending to it.

    kernel cache always varies by the complete query-string and never varies by header, you do not have the option of configuration query-string/header vary with kernel-cache.

     

    Anil Ruia
    Senior Software Design Engineer
    IIS Core Server
  • 08-06-2009, 2:15 PM In reply to

    Re: IIS7 Caching Difficulties

    Thanks anilr, that makes a lot of sense. Do you know what the default for user-mode caching is in regards to varyByQueryString? I'm assuming that omitting it and enabling kernel mode and user mode caching will result in both varying by the complete querystring, but I can't be completely sure based on the documentation.

    I was using IIS 7.5 RC (Windows 7 RC) on my development machine. I retested on Windows 2008 SP2 and one of the bugs went away. I'll retest on IIS 7.5 RTM once the MSDN download finishes today.

    Here are the reproduction steps for the cache-control issue I saw:

    1. Create an ASPX page and put the following in the Page_Load event handler:
      Response.Cache.SetCacheability(HttpCacheability.Private);
      Response.Cache.SetMaxAge(
      new TimeSpan(0, 0, 30));
    2. Load the page and look at the response headers. "Cache-Control: private, max-age=30" will be set.
    3. Open the web.config, add the following:
      <system.webServer>
        <
      caching>
          <
      profiles>
            <
      add extension=".aspx" policy="CacheForTimePeriod" kernelCachePolicy="DontCache" duration="00:00:30" />
          </
      profiles>
        </
      caching>
      </
      system.webServer>
    4. Refresh the page and look at the response headers.

    Results:

    • Windows 2008 SP2 / IIS 7.0: Cache-Control header is set to "private, max-age=30" (correct)
    • Windows 7 RC / IIS 7.5: Cache-Control header is set to "no-cache,private, max-age: 30" (incorrect)
  • 08-06-2009, 4:02 PM In reply to

    • anilr
    • Top 10 Contributor
    • Joined on 05-23-2006, 6:13 PM
    • Redmond, WA
    • Posts 2,343

    Re: IIS7 Caching Difficulties

    Please check the exact version (including build number) of asp.net on the ws08sp2 vs the ws08r2rc machines - you should be able to get both to the same asp.net by installing .net 3.5 sp1.

    Anil Ruia
    Senior Software Design Engineer
    IIS Core Server
  • 08-06-2009, 4:34 PM In reply to

    Re: IIS7 Caching Difficulties

    Windows 7 RC machine: C:\Windows\Microsoft.NET\Framework64\v2.0.50727\aspnet_isapi.dll: 2.0.50727.4918. AppPool is configured to 2.0.50727 Integrated Pipeline. (64bit).

    Windows 2008 SP2 machine: C:\Windows\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll: 2.0.50727.4016. AppPool is configured to 2.0.50727 Integrated Pipeline. (32bit).

  • 08-10-2009, 12:27 PM In reply to

    Re: IIS7 Caching Difficulties

    Tested Windows 7 RTM - aspnet_isapi.dll 2.0.50727.4927

    Case #1:

    • Output caching enabled, set to location="any"
    • Kernel caching: enabled
    • App pool caching: enabled
    • Application sets Cache-Control: public, max-age: 1209600

    Result: Failed. Cache-Control header equal to "public,public, max-age: 1209600"

    Case #2:

    • Output caching enabled, set to location="any"
    • Kernel caching: enabled
    • App pool caching: disabled
    • Application sets Cache-Control: Public, max-age: 1209600

    Results: Succeeded. Cache-Control header equal to "public, max-age: 1209600".

     

    Based on the results, IIS 7.5 RTM appears to have the bug as well. The issue only affects user-mode caching.

Page 1 of 1 (8 items)
Microsoft Communities