0
votes

I'm writing a Flex app using REST requests and trying to avoid HTTP caching as well as synchronize client/server time. To this end I've created a timestamp property as such:

// returns a timestamp corrected for server time            
private function get timestamp() : Number
{
    return new Date().getTime() + clientClockAdjustMsec;
}

(The clientClockAdjustMsec I've already set using special mojo)

I also attempt to include the timestamp in my query string like this:

<mx:HTTPService url="/Service?ts={timestamp}" ...

But what I see in the access logs is weird. It's something like this:

1.2.3.4 - - [06/Aug/2009:17:19:47 +0000] "GET /Service?ts=1249579062937 HTTP/1.1" 200 478
1.2.3.4 - - [06/Aug/2009:17:20:13 +0000] "GET /Service?ts=1249579062937 HTTP/1.1" 200 500
1.2.3.4 - - [06/Aug/2009:17:20:14 +0000] "GET /Service?ts=1249579062937 HTTP/1.1" 200 435

See how the timestamps are all the same? So strange. I would expect it to evaluate the property every time, as it does for Bindable variables.

(Actually, I just checked again and it does do the same thing for Bindable variables. But not with all clients. Do some versions of Flash have "issues"?)

2

2 Answers

1
votes

so this is a read only getter? Binding isn't going to update {timestamp} in your HTTPService component as it has no property to bind to. timestamp is the output of a function (as Christopher mentions below) and is not a Bindable property. You need to either create a bindable property, or explicitly set the URL with a current timestamp, avoiding binding altogether.

Someplace in your code you are using myService.send(), you need to do something like:

[Bindable]
private var timestamp:Number;

private function whereSendHappens():void
{
    timestamp = new Date().getTime() + clientClockAdjustMsec;
    myService.send()
}

<mx:HTTPService url="/Service?ts={timestamp}" ...

if for some reason that didn't work:

private function whereSendHappens():void
{
    timestamp = new Date().getTime() + clientClockAdjustMsec;
    myService.url = "/Service?ts=" + timestamp;
    myService.send();
}

thus avoiding any binding issues...

1
votes

The other thing you can do is make the get function bindable to a specific event.

[Bindable("updateTimestamp")]
public function get timestamp() : Number { ... }

public function whereSendHappens():void
{
    dispatchEvent(new Event("updateTimestamp")); // will cause the binding to fire
    myService.send();
}