locked
WinJS.xhr Not caching the responses.

    Question

  • Hi All,

    I am using WinJS.xhr for consuming web services in my App.

    As per the microsoft documents WinJS.xhr will cache the responses But actually  WinJS.xhr not caching the url responses.

    Below is the UseCase

    • My app is connected to the internet and user opens it.
    • User navigated to HomePage. Content retrieved from web service is shown on the HomePage.
    • Now user closes the app and disconnects internet connection.
    • User starts my App and he/she navigated to HomePage.
    • But this time the WinJS.xhr error method is called.

    Can anyone guide me for this scenario.

    Below is the code I am using.

    var apiurl = "any get request url";
    var requestHeaders = {
                                    email_id: devEmailId,
                                    partner_id: URLS.CHANNELID,
                                    channel_id: URLS.PARTENERID,
                                    developer_api_key :devApiKey,
                                };
    var   xhrCall = WinJS.xhr({ url: apiurl, headers: requestHeaders });
    
    xhrCall.done(function complete(result) {
        console.log("successfull  winjs xhr call");
    },function error(result){
        console.log("error in winjs xhr call");
    });

    Please guide me.I am stuck for almost 15 days.


    Wednesday, October 16, 2013 12:42 PM

Answers

  • Hi Ashwin,

    I noticed that there is a word from you: the user close the app and disconnect the internet. 

    So what you mean is you use WinJS.xhr to fetch the data and want to use the data for next time if there is no Internet access?

    I don't think its possible by WinJS.xhr, the "cache" can be only used for this time, when the app close, the cache saved by WinJS.xhr will be cleaned. The same thing can be found on HTML, have you ever see after you close an AJAX HTML, the next time you open it, the data still exist without Internet connection?

    The suggestion provided by Mike comes from this link: How to ensure that WinJS.xhr resends requests. The main idea is to resend the xhr request due to the system hold the cache.

    And the possible solution for you I think is to save the data you fetched by xhr locally and the next time user open the app, use these data. ref: http://msdn.microsoft.com/en-us/library/windows/apps/hh700820.aspx

    Best Regards,

    --James



    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.



    Saturday, October 19, 2013 2:29 AM
    Moderator

All replies

  • You might try using the "If-Modified-Since" attribute in the header to see if that solves the problem. I recall that this solved a caching issue with WinJS.xhr in my code.

    "If-Modified-Since": "Mon, 27 Mar 1972 00:00:00 GMT"

                 
    Wednesday, October 16, 2013 5:50 PM
  • HI Mike,

    I tried it but it is not working.

    Thanks

    Friday, October 18, 2013 1:40 PM
  • Hi Ashwin,

    I noticed that there is a word from you: the user close the app and disconnect the internet. 

    So what you mean is you use WinJS.xhr to fetch the data and want to use the data for next time if there is no Internet access?

    I don't think its possible by WinJS.xhr, the "cache" can be only used for this time, when the app close, the cache saved by WinJS.xhr will be cleaned. The same thing can be found on HTML, have you ever see after you close an AJAX HTML, the next time you open it, the data still exist without Internet connection?

    The suggestion provided by Mike comes from this link: How to ensure that WinJS.xhr resends requests. The main idea is to resend the xhr request due to the system hold the cache.

    And the possible solution for you I think is to save the data you fetched by xhr locally and the next time user open the app, use these data. ref: http://msdn.microsoft.com/en-us/library/windows/apps/hh700820.aspx

    Best Regards,

    --James



    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.



    Saturday, October 19, 2013 2:29 AM
    Moderator