locked
IXMLHTTPRequest2 and caching is broken

    Question

  • It looks like IXMLHTTPRequest2 is caching downloaded content regardless of the headers I add to the request. I have tried "Cache-Control: no-cache", "Cache Control: no-store", and "Pragma: no-cache". None of them are honored by the API, it still retrieves downloaded content from the cache instead of from the server.

    In the File Explorer I see the XHR2 data cache in the "AC" subdirectory of my app's Local Package directory.

    Is there some sort of flag or other setting I can use to make IXHR2 stop caching content and *always* go to the server for data. This is a showstopper bug for my program, which downloads and displays real-time text and binary data from various internet servers.

    Thanks

    Saturday, October 27, 2012 6:33 PM

Answers

  • Hello Henador,

    You can force XHR to retrieve the latest content by setting the "If-Modified-Since" HTTP header in the request and set a time in the past. 

    If you have control over the server response, you could send back an Expires HTTP response header with a value 0 or a date in the past. That should make XHR retrieve the latest response for you.

    You are only required to do one of the above, changing both the client and server side code is not necessary.

    The client side code could be changed to something like this:

    xhr->Open(...)

    xhr->SetRequestHeader(L"If-Modified-Since", L"Sat, 01 Jan 2000 00:00:01 GMT");

    xhr->Send(...)

    For changing the server side behavior if your server side code is based on ASP.net you could change your response header like this:

    Response.Headers.Add("Expires", "0")

    Thanks,

    Prashant.

    Tuesday, October 30, 2012 12:03 AM
    Moderator

All replies

  • Looks like this is a known "limitation" of the internet access in WinRT:

    http://social.msdn.microsoft.com/Forums/en-US/winappswithcsharp/thread/f00e1c9c-9214-48fc-b0f2-2d39d8b8039c

    Just unbelievable. Maybe I'll have to resort to damn sockets for simple http handling.

    Sunday, October 28, 2012 2:31 AM
  • Hello Henador,

    You can force XHR to retrieve the latest content by setting the "If-Modified-Since" HTTP header in the request and set a time in the past. 

    If you have control over the server response, you could send back an Expires HTTP response header with a value 0 or a date in the past. That should make XHR retrieve the latest response for you.

    You are only required to do one of the above, changing both the client and server side code is not necessary.

    The client side code could be changed to something like this:

    xhr->Open(...)

    xhr->SetRequestHeader(L"If-Modified-Since", L"Sat, 01 Jan 2000 00:00:01 GMT");

    xhr->Send(...)

    For changing the server side behavior if your server side code is based on ASP.net you could change your response header like this:

    Response.Headers.Add("Expires", "0")

    Thanks,

    Prashant.

    Tuesday, October 30, 2012 12:03 AM
    Moderator
  • Prashant,

    Thanks for the reply. I was able to get one of my private data sources (which are all outside my control, some are private companies and others are government servers) to add in Cache-Control statements in their responses. XHR2 honored those headers. I have no hope of getting the government servers to change their responses.

    I've worked around the local caching issue with URL junk and I'll probably switch to If-Modified-Since once I get the code written to keep track of the LMT. The remaining issue is the local cache itself. I see a total of ~50MB in the INetCache directories going back to 10/27. What is the limit on the size and/or age of the data kept in XHR2's cache? I don't want it filling up my users' disks, which are usually limited in size on tablets and phones. It's a waste of space since I already keep copies of the required data in my app's data directory.

    Tuesday, October 30, 2012 5:20 AM
  • Hi Henador,

    You can be rest assured that the system keeps track of the cache and the size of the cache will not go beyond certain limits. The system will also periodically cleans up the cache so you will not have to worry about running out of disk space.

    Thanks,

    Prashant.

    Wednesday, October 31, 2012 5:09 PM
    Moderator
  • You can be rest assured that the system keeps track of the cache and the size of the cache will not go beyond certain limits. The system will also periodically cleans up the cache so you will not have to worry about running out of disk space.

    We are experiencing this problem in a Windows 8 application, the cache located at "C:\Users\<username>\AppData\Local\Microsoft\Windows\Temporary Internet Files\Content.IE5" is filled up until the disk is full. We use the same IXMLHTTPRequest2 methods as the OP.

    Could you advise on that?

    Thursday, December 13, 2012 1:54 PM
  • Fueled13,

    The location you are referring to is not the cache location for Windows Store apps. You are referring to the desktop IE cache location, so you are referring to a different problem.

    The IE cache is getting filled up is an independent problem than using IXMLHttpRequest2 from Windows Store app.

    If you are still experiencing the problem, I would recommend that you post your problem to the IE forum: http://social.msdn.microsoft.com/Forums/en-US/iewebdevelopment/threads or open up a support case with our IE team to investigate further.

    Thanks,

    Prashant.

    Thursday, January 10, 2013 11:32 PM
    Moderator
  • New in Windows 8.1: the Windows.Web.Http HttpClient API.  This is an easy-to-use, full-featured HTTP API that works in all languages: C++, .NET (C#, VB) and JavaScript.    Advantages of the new API include: strongly typed headers (meaning: you write fewer bugs in less time), full support for standard WinRT async concepts and data types.

    HttpClient also lets you inject your modular filter code into the HTTP processing pipeline, letting you handle logging, testing, retry and auth more naturally.  Samples of filters include retry and metered network filters in the HttpClient sample, and OAUTH and OAUTH 2.0 support in the Web Authentication Broker sample.

    (Note that the existing IXHR2 code is still available for developers, and your existing Windows 8 code should continue to work as expected)

    There's a //build/ 2013 video for the new API at http://channel9.msdn.com/Events/Build/2013/4-092

    We also have samples at http://code.msdn.microsoft.com/windowsapps/HttpClient-sample-55700664

    There's an OAUTH 0 filter sample at http://code.msdn.microsoft.com/windowsapps/Web-Authentication-d0485122

    And there's documentation at http://msdn.microsoft.com/en-us/library/windows/apps/windows.web.http.aspx


    Network Developer Experience Team (Microsoft)

    Tuesday, July 16, 2013 9:35 PM