Flash 不再缓存 PHP?
Flash doesn't cache PHP anymore?
我正在从我的服务器加载这个 PHP 文件:
<?php
echo date('z Y H:i:s');
?>
而且我总是得到当前时间,而不是缓存的旧时间。我正在正常加载它,地址末尾没有任何 "?"+Math.random()
。
谁能确认 Flash 有意不再缓存 .php 文件?还是我弄错了什么?
编辑:
我不知道这是否澄清了事情或使他们更加困惑,但这是我的 PHP 加载 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);
}
}
}
无论我将 skipCache
设置为 true 还是 false,我都会得到相同的未缓存结果。
Flash 与缓存无关HTML。它是 HTTP 响应头(例如 max-age、pragma、expiration、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 link。
而不是 <a href="page.php">>Link Text</a>
<form action="page.php" method="post"><button>Link Text</button></form>
我正在从我的服务器加载这个 PHP 文件:
<?php
echo date('z Y H:i:s');
?>
而且我总是得到当前时间,而不是缓存的旧时间。我正在正常加载它,地址末尾没有任何 "?"+Math.random()
。
谁能确认 Flash 有意不再缓存 .php 文件?还是我弄错了什么?
编辑:
我不知道这是否澄清了事情或使他们更加困惑,但这是我的 PHP 加载 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);
}
}
}
无论我将 skipCache
设置为 true 还是 false,我都会得到相同的未缓存结果。
Flash 与缓存无关HTML。它是 HTTP 响应头(例如 max-age、pragma、expiration、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 link。
而不是 <a href="page.php">>Link Text</a>
<form action="page.php" method="post"><button>Link Text</button></form>