views:

588

answers:

2

I'm writing a flex application that polls an xml file on the server to check for updated data every few seconds, and I'm having trouble preventing it from caching the data and failing to respond to it being updated.

I've attempted to set headers using the IIS control panel to use the following, without any luck:

CacheControl: no-cache
Pragma: no-cache

I've also attempted adding a random HTTP GET parameter to the end of the request URL, but that seems like it's stripped off by the HttpService class before the request is made. Here's the code to implement it:

http.url = "test.xml?time=" + new Date().getMilliseconds();

And here's the debug log that makes me think it failed:

(mx.messaging.messages::HTTPRequestMessage)#0
  body = (Object)#1
  clientId = (null)
  contentType = "application/x-www-form-urlencoded"
  destination = "DefaultHTTP"
  headers = (Object)#2
  httpHeaders = (Object)#3
  messageId = "AAB04A17-8CB3-4175-7976-36C347B558BE"
  method = "GET"
  recordHeaders = false
  timestamp = 0
  timeToLive = 0
  url = "test.xml"

Has anyone dealt with this problem?

+2  A: 

The cache control HTTP header is "Cache-Control" ... note the hyphen! It should do the trick. If you leave out the hyphen, it is not likely to work.

Chris W. Rea
A: 

I used the getTime() to make the date into a numeric string that did the trick. I also changed GET to POST. There were some issues with different file extensions being cached differently. For instance, a standard dynamic extension like .php or .jsp might not be cached by the browser and

private var myDate:Date = new Date();
[Bindable]
private var fileURLString:String = "http://www.mysite.com/data.txt?" + myDate.getTime();

Hopefully this helps someone.

I also threw a ton of the header parameters at it but they never fully did the trick. Examples:

// HTTPService called service
service.headers["Pragma"] = "no-cache";  // no caching of the file
service.headers["Cache-Control"] = "no-cache";
Dylan