Reputation: 3368
I am loading this PHP file from my server:
<?php
echo date('z Y H:i:s');
?>
and I always get the current time rather than an old, cached one. I am loading it normally, without any "?"+Math.random()
at the end of its address.
Can anyone confirm that Flash intentionally no longer caches .php files? Or do I get something wrong?
Edit:
I don't know if this clarifies things or perplexes them more, but here is my PHP loading class:
package fanlib.utils
{
import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.net.URLLoader;
import flash.net.URLLoaderDataFormat;
import flash.net.URLRequest;
import flash.net.URLRequestHeader;
import flash.net.URLRequestMethod;
import flash.utils.Dictionary;
public class QuickLoad
{
static private const DONT_GC:Dictionary = new Dictionary();
private var funcLoaded:Function;
public function QuickLoad(file:String, funcLoaded:Function, format:String = URLLoaderDataFormat.TEXT, skipCache:Boolean = false)
{
DONT_GC[this] = this;
this.funcLoaded = funcLoaded;
const loader:URLLoader = new URLLoader();
loader.dataFormat = format;
loader.addEventListener(Event.COMPLETE, loadComplete);
loader.addEventListener(IOErrorEvent.IO_ERROR, error);
const request:URLRequest = new URLRequest(file);
if (skipCache) {
const header:URLRequestHeader = new URLRequestHeader("pragma", "no-cache");
// request.data = new URLVariables("cache=no+cache");
request.method = URLRequestMethod.POST;
request.requestHeaders.push(header);
}
loader.load(request);
}
private function loadComplete(e:Event):void {
var loader:URLLoader = e.target as URLLoader;
loader.removeEventListener(Event.COMPLETE, loadComplete);
loader.removeEventListener(IOErrorEvent.IO_ERROR, error);
funcLoaded(loader.data);
delete DONT_GC[this]; // get me now
funcLoaded = null;
}
private function error(e:IOErrorEvent):void {
trace(this, e.text);
}
}
}
I get the same uncached result whether I am setting skipCache
to either true or false.
Upvotes: 0
Views: 89
Reputation: 5665
Flash has nothing to do with the cached HTML. It is the HTTP Response Header (e.g. max-age, pragma, expiration, ETag) and the method used to load the page (e.g. POST Requests do not cache, Refresh may override cache)
Have you tried:
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
header("Expires: Sun, 1 Mar 2015 00:00:00 GMT");
header("Cache-Control: max-age=0");`
Or if you could use a POST link.
Rather than <a href="page.php">>Link Text</a>
<form action="page.php" method="post"><button>Link Text</button></form>
Upvotes: 1