3 Replies Latest reply on Sep 21, 2006 1:25 PM by peterent

    httpservice caching content problem

    refactor1
      I have tried to set cache controls in the header for an httpservice but it does not appear to work. here is the code.

      var dataService:HTTPService = new HTTPService();
      var headers:Array = new Array("pragma: no-cache");

      dataService.method = "POST";
      dataService.url = "servlet/dwservlet?requestAction=loadTemplates";

      dataService.addEventListener(ResultEvent.RESULT,_responder.onResult);
      dataService.addEventListener(FaultEvent.FAULT,_responder.onFault);
      dataService.headers=headers;
      dataService.send();

      This does not work. I have also tried "Cache-Control: no-cache" and this does not work. I have also tried to mix up the syntax to be new Array("Cache-Control", "no-cache") and this does not work.

      Does anybody have any ideas? The only thing that seems to work is to make the url of the service have a unique url each time by putting a random number in the parameter string, this is really not an option because the content recieved from the url is quite large and would be cached in the browser for each request.

      HELP! Thanks
        • 1. Re: httpservice caching content problem
          peterent Level 2
          This is a bit of a hack and I'm checking into the headers option now. But this should work:

          dataService.url = "servlet/dwservlet?requestAction=loadTemplates&dummy="+(new Date()).time;

          This puts a unique dummy parameter to the request and fools the browser because the browser sees that the URL is unqiue - it is the URL that browser uses to determine if it should cache the result or not.

          This assumes your servlet won't complain about an extra parameter.
          • 2. Re: httpservice caching content problem
            refactor1 Level 1
            Yes the dummy parameter works but is not suitable because if the response, in this case xml, is very large it will fill up the user cache fairly quickly since every request is unique. Please help with setting headers.
            • 3. Re: httpservice caching content problem
              peterent Level 2
              Turns out that you have to do this from the server-side. It is the server response header's that tell the browser not to cache the data.

              When you request a plain file, such as an XML file, there isn't any way to get the server to stuff the response header with the no-cache option. That is, unless there is a way for the web server or app server to have a default value.

              To do this, you'd have to request your file via PHP, JSP, or something that can change the response header.

              Since you are using a servlet you should be able to get that to modify the response header to include Cache-control: no-cache (as well as Pragma and Expires - you should do them all in case one browser doesn't recognize your option).