我正在从我的服务器加载这个PHP文件:
<?php
echo date('z Y H:i:s');
?>
我总是得到当前的时间,而不是旧的、缓存的时间。我正在正常加载它,在它的地址末尾没有任何"?"+Math.random()
。
有人能证实Flash有意不再缓存.php文件吗?或者我做错了什么?
编辑:
我不知道这是澄清了问题还是让他们更加困惑,但这是我的PHP加载类:
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);
}
}
}
无论将skipCache
设置为true还是false,我都会得到相同的未缓存结果。
Flash与缓存的HTML无关。它是HTTP响应标头(例如,最大期限、杂注、过期、ETag)和用于加载页面的方法(例如,POST请求不缓存,刷新可能覆盖缓存)
你试过吗:
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");`
或者您是否可以使用POST链接。而不是<a href="page.php">>Link Text</a>
<form action="page.php" method="post"><button>Link Text</button></form>