|
![]() |
名片设计 CorelDRAW Illustrator AuotoCAD Painter 其他软件 Photoshop Fireworks Flash |
|
当WML页面下载到WAP设备后,它将保存在WAP设备内存中一段时间,直到这个时间过期。在这之后,页面将从服务器下载,而不是从WAP设备的缓存读取。这个过程被称做Cache。 但是有些时候不想让页面从缓存中读取,而是从服务器端读取。一个典型的例子就是当服务器的内容不断在更新的时候,通过在HTTP头中加入一定的cache信息,来告诉WAP设备该页面将不存储在缓存中。 可以在服务器端生成HTTP头,或者使用PHP、ASP、Perl或者其他服务端开发语言。这一行不能被包括在页面里,既然是HTTP的信息头,就不是WML元素。 对于静态页面,或许没有使用服务器端脚本语言,许多浏览器支持META标签来控制浏览器的Cache。看本部分的最后的例子。 将下面代码加入到HTTP头中,页面将立刻过期: Expires: Mon, 26 Jul 1997 05:00:00 GMT Last-Modified: DD. month YYYY HH:MM:SS GMT Cache-Control: no-cache, must-revalidate Pragma: no-cache 第一行告诉微型浏览器,页面已经过期一段时间了。第二行告诉浏览器页面最后一次修改的时间。DD应该换成当天的日期,month YY HH MM SS等等类推。第三行和第四行有同样的效果。告诉浏览器页面不被Cache(第三行适用于 HTTP 1.1,第四行适用于HTTP 1.0)。 下面的是PHP的一个例子: <? // set the correct MIME type header("Content-type: text/vnd.wap.wml"); // expires in the past header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Last modified, right now header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // Prevent caching, HTTP/1.1 header("Cache-Control: no-cache, must-revalidate"); // Prevent caching, HTTP/1.0 header("Pragma: no-cache"); ?> 下面是使用WebClasses(VB)的例子。使用"Response.Expires=-1",防止Cache。 Private Sub WebClass_Start() \\'Set correct MIME type Response.ContentType = "text/vnd.wap.wml" \\'Make sure no caching Response.Expires = -1 Response.AddHeader "Pragma", "no-cache" Response.AddHeader "Cache-Control", "no-cache, must-revalidate" \\'Use basicwml(my own) as template Set NextItem = basicwml End Sub 这里有一个ASP的例子,同样使用“Response.Expires=-1”防止Cache。 <% Response.ContentType = "text/vnd.wap.wml" Response.Expires = -1 Response.AddHeader "Pragma", "no-cache" Response.AddHeader "Cache-Control", "no-cache, must-revalidate" %> 最后是使用META的例子: <?xml version="1.0"?> <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "\\' target=_blank>http://www.wapforum.org/DTD/wml_1.1.xml"> <wml> <head> <meta forua="true" http-equiv="Cache-Control" content="max-age=0"/> </head> <card id="alwaysexpire"> <p>This deck will never be stored in the cache</p> </card> </wml> 下面的页面是在经过86400秒(24 hours)后过期。 <?xml version="1.0"?> <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "\\' target=_blank>http://www.wapforum.org/DTD/wml_1.1.xml"> <wml> <head> <meta forua="true" http-equiv="Cache-Control" content="max-age=86400"/> </head> <card id="expire1day"> <p>This card will live in the cache for a day</p> </card> </wml> 有些浏览器例如:UP.Simulator假如可以通过“返回”达到另外一个卡片,那么它将不会重新装载卡片。为了强制这个更新动作,用户必须在META标签中使用must-revalidate 参数。 <meta forua="true" http-equiv="Cache-Control" content="must-revalidate"/> 返回类别: 教程 上一教程: 用PHP读取IMAP邮件 下一教程: 模仿OICQ的实现思路和核心程序(二) 您可以阅读与"怎样防止从Cache中读取WML页面"相关的教程: · PHP怎样调用MSSQL的存储过程 · 建立动态的WML站点(一) · 使用mod_gzip加速你的html页面 · 怎样校验输入的日期为合法的日期?这里有一个例子(checkdate.php3) · 取得页面所有不重复连接的函数 |
![]() ![]() |
快精灵印艺坊 版权所有 |
首页![]() ![]() ![]() ![]() ![]() ![]() ![]() |