On May 17, I ran into a frustrating situation with the Fanfou AIR client: “after AIR opens an XML file, it caches it, so it can’t refresh in time.” As I’d imagined it, I just needed to click a button to refresh the network data, but the data was cached — AIR preferred the local data and wouldn’t update in time. Very annoying. In the end I had to resort to “unorthodox measures” —
To deal with this kind of failure to refresh due to caching, there’s a trick: add a parameter to the requested URL. For example, if you’re requesting a.xml?user=b, then every time you need to refresh, change it to request a.xml?user=b&r=1. Increment the value of r by 1 each time, and with this little hack you can get the data to refresh.
Today I poked around the official site and found that URLRequest in AIR apps has two properties that can handle this (finally, something that stands up for us common folk~). They are:
cacheResponse useCache
cacheResponse sets whether to cache the data after a successful response, and defaults to true. useCache sets whether to look for locally cached data first, and also defaults to true. Both properties can also be given default values in the URLRequestDefaults class.
From now on I’ll know to just turn off caching for URL requests I don’t want cached. Also, since I’ve never worked with it, I don’t yet know where HttpService data caching falls under in Flex. Anyone know? Tell me…