« Previous Next »

Thread: How to set cache control for static content

Last post 07-15-2009 9:13 PM by anilr. 17 replies.

Average Rating Rate It (5)

RSS

Page 1 of 2 (18 items) 1 2 Next >

Sort Posts:

  • 01-25-2007, 4:04 PM

    • pkorona
    • Not Ranked
    • Joined on 01-25-2007, 8:56 PM
    • Posts 1

    How to set cache control for static content

    I would like to set a maxage value for entities in my images directory, but I can find no way to do so. The IIS 7.0 Beta help indicates there should be a UI element for HTTP Headers, but there is none. None of the release documentation mentions this element.

    I tried using appcmd as well, but it didn't seem to have any effect.

    Currently the Last-Modified header is returned, so subsequent requests respond with 304 (Not Modified), but I would like the browser to just use it's local cache most of the time.

     Thanks

  • 01-26-2007, 4:38 PM In reply to

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

    Re: How to set cache control for static content

    This property is not exposed in the UI - you can set it using appcmd - eg to set max-age to 1hr for all static files under /images on default-web-site, run the following

    \Windows\system32\inetsrv\appcmd.exe set config "Default Web Site/images" -section:system.webServer/staticContent -clientCache.cacheControlMode:UseMaxAge

    \Windows\system32\inetsrv\appcmd.exe set config "Default Web Site/images" -section:system.webServer/staticContent -clientCache.cacheControlMaxAge:"01:00:00"

    Anil Ruia
    Senior Software Design Engineer
    IIS Core Server
  • 11-23-2007, 8:44 AM In reply to

    Re: How to set cache control for static content

    Is it possible to cache static content with IIS 5 or 6?
  • 02-27-2008, 2:40 PM In reply to

    • Galcho
    • Not Ranked
    • Joined on 04-11-2005, 1:48 PM
    • Posts 4

    Re: How to set cache control for static content

    here is a further research on the subject: IIS7: How to set cache control for static content?

    Hope this helps

    Galin Illiev
    www.galcho.com
  • 07-12-2008, 12:23 PM In reply to

    • jimrPA
    • Top 100 Contributor
    • Joined on 06-02-2008, 1:20 PM
    • Posts 62

    Re: How to set cache control for static content

    Is there a way to disable static caching on a site level? Or set the caching period for the entire site and not each folder?

  • 07-16-2008, 1:42 PM In reply to

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

    Re: How to set cache control for static content

    Are you talking about server-side caching or client-side caching?  The posts above already talk about client-side caching, for server-side caching, you can do the following

    appcmd set config "My Site" -section:system.webServer/caching -enabled:false

     

    Anil Ruia
    Senior Software Design Engineer
    IIS Core Server
  • 07-16-2008, 5:25 PM In reply to

    • jimrPA
    • Top 100 Contributor
    • Joined on 06-02-2008, 1:20 PM
    • Posts 62

    Re: How to set cache control for static content

    that's it, thanks

  • 08-25-2008, 12:20 AM In reply to

    Re: How to set cache control for static content

    Hello Anilr,

    I am totally frustrated at this caching deal.

    I was originally using IIS 5.1 on Windows XP.  To turn the Cashe ISAPI applications

    check box off from the command line prompt, I would type in

    cscript.exe adsutil.vbs set w3svc/1/root/myWebApp/cacheisapi 0

    This would effectively turn off the IIS caching, and so when I replace the DLL file in the GAC, (Global Assembly Cache), the change would take effect right away.  This means the IIS 5.1 was not cashing the dll in memory.  This worked great!  So now I have the ability to replace the DLL in the GAC and the IIS server would serve the fresh content right away without having to reset IIS.  However this line does "not" work as far as I have tried in IIS 7.0.

    I tried your suggestion of this as well from the command line prompt, for IIS 7.0:

    appcmd set config "Default Web Site/myWebApp" -section:system.webServer/caching -enabled:false

    and it returned:

    "Applied configuration changes to section......."

    So it executes, but still does not prevent caching of the DLL.  I would like to mimik the same thing I had for IIS 5.1 (in win-xp) for IIS 7.0 (in VISTA), but have spent endless hours wondering how to get it done.  If your suggestion works, I should be able to reoplace a DLL in the GAC with the same name, version and build, and IIS should "not" cache it, therefore allowing the webpage that utilizes that DLL in the GAC to reflect any new changes instantly.  It works in win-xp, so why does it not work in vista?

    **Please help!.... Thanks in advance,

    theadmirableone

     

  • 08-26-2008, 5:27 PM In reply to

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

    Re: How to set cache control for static content

    This thread was about caching of responses on the client - you are talking about dlls on the server in memory - also, ISAPI extensions in the GAC does not make any sense.

    Anil Ruia
    Senior Software Design Engineer
    IIS Core Server
  • 08-28-2008, 11:08 AM In reply to

    Re: How to set cache control for static content

    Anilr,

    Let me be clear about what I am trying to do.

    Let's suppose that caching ISAPI is enabled for a particualt web app. on the IIS 5.1.  If I place a .dll in the GAC and then call it from that web application in ASP.NET 2.0, then all is fine. 

    However, if I go to rebuild that .dll from within ASP.NET 2.0 to return a different hard coded string, and then replace the original .dll in the GAC, (effectively replacing the oringinal .dll with the same assembly version and build),  IIS does not see the different string when I call the .dll because it caches the .dll.  That is why I use:  "cscript.exe adsutil.vbs set w3svc/1/root/myWebApp/cacheisapi 0" (without quotes), to disable the ISAPI cache.  When this is done, and IIS is reset, IIS 5.1 does not cache the .dll in the GAC anymore.  This means that when no matter how "many" times I rebuild my .dll in ASP.NET 2.0 with different hard coded strings to return and place that new .dll in the GAC, (with the same assembly version and build), the new string will always show when that .dll is being called from any app.  This is becuase caching is turned off at the ISAPI level.

    I have tried this scenario dozens of times, and it certainly resolves the issue of replacing the same .dll in the GAC, (with the same assembly version and build), and still getting the new hard coded string, simply becuase the Cache ISAPI was turned off for that particular website.

    If I were to leave the cache ISAPI on, then IIS caches the .dll and will never retrieve the new string, even after I rebuild my ASP.NET 2.0 .dll and replace it in the GAC with same assembly and version.

    I could use a differenct assembly and build version, instead of turning off the ISAPI cache to resolve it, however I would like to use the same (assembly and build version).

    So the question I pose to you is: how do I turn off ISAPI cache in IIS7, as "cscript.exe adsutil.vbs set w3svc/1/root/myWebApp/cacheisapi 0" (without quotes), does nothing for me in IIS 7?

    thanks ahead of time, theadmirableone

  • 08-29-2008, 4:28 PM In reply to

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

    Re: How to set cache control for static content

    Disabling caching of ISAPIs has not been supported since IIS6.

    What you were ending up doing on IIS5.1 is to load and unload all of asp.net and .net framework (and the asp.net worker process) after every request.  You can achieve the same effect by recycling the application pool when you want by running

    %windir%\system32\inetsrv\appcmd.exe recycle apppool "DefaultAppPool" (replace name of app-pool you want)

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

    Re: How to set cache control for static content

    Well Anil.R you are correct!  :~)  Hats-off to you!

    After so many days of trying to get this to work without reseting IIS, your suggestion works. 

    The remaining question is:  If I use your suggested process/command after creating a distinct app pool for this particular web app, (so that the other app pools are not effected), does this command also destroy the session variables that the IIS7 might be currently using, in production, or does it simply clear the cache?

     thanks a million, theadmirableone

  • 09-03-2008, 2:15 PM In reply to

    • andrewbi
    • Top 150 Contributor
    • Joined on 03-08-2007, 10:01 PM
    • Posts 41

    Re: How to set cache control for static content

    Recycling the app pool will destroy any session variables for ASP.NET applications running in that particular app pool but will leave other apps running in other app pools alone.

    Andrew Birck
    Microsoft Developer, IIS
  • 10-05-2008, 6:36 PM In reply to

    • afjk
    • Not Ranked
    • Joined on 10-05-2008, 8:36 PM
    • Posts 5

    Re: How to set cache control for static content

     Thanks! Hopefully this info will help reduce the load on my webserver .. its starting to get a bit overstressed!

    AF

  • 12-08-2008, 9:59 AM In reply to

    Re: How to set cache control for static content

    Well. Thanks for great information. I have a question though:

     If I enabled static filecaching on a specific directory, i.e:

    appcmd.exe set config "Default Web Site/images" -section:system.webServer/staticContent -clientCache.cacheControlMode:UseMaxAge

    Then, how am I able to remove it again ?

    The funny thing is, I have a .css file in a directory where I did the exact thing above, and max age is set to 84600, but even its the 8. december today, and I make sure my temporary Internet Files etc. is deleted, my browser still sees this .css file as being from the 28. november, even the file is build today. This really worries me, as I see no way to get around this, recycling application pools or not.

    Any help is really appreciated.

    Best, Lars

Page 1 of 2 (18 items) 1 2 Next >
Microsoft Communities