当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的例子:
br>' target=_blank>http://www.wapforum.org/dtd/wml_1.1.xml>
this deck will never be stored in the cache
下面的页面是在经过86400秒(24 hours)后过期。
br>' target=_blank>http://www.wapforum.org/dtd/wml_1.1.xml>
this card will live in the cache for a day
有些浏览器例如:up.simulator如果可以通过“返回”达到另外一个卡片,那么它将不会重新装载卡片。为了强制这个更新动作,用户必须在meta标签中使用must-revalidate 参数。