|
How do I prevent a WML deck from being read from the cache? |
|
After a WML deck has
been downloaded to the WAP device, it lives in the WAP device's memory for a certain
period of time. Until this period has expired, the deck will not be downloaded from the
server but instead from the WAP device memory. This is known as caching, and it obviously
speeds things up considerably.
However, in some rare cases you might not want the deck to be read from the cache memory
but from the server. A typical case is where you have a deck containing cards with
information that gets updated frequently. By adding some cache information to the HTTP
header you send out from the server, you can tell the WAP device that the following deck
should never be stored in the cache.
Note that this requires that you are able to produce HTTP headers on the server side,
either using PHP, ASP, Perl or some other type of server side scripting language. The
lines cannot be included in the deck code as they are HTTP header information, not WML
elements.
IMPORTANT! For static decks, or if you do not have access to a server side
script language, many browsers support META tags that control caching on the browser. See
the end of this section for examples on using META tags for controlling the cache.
See the W3C HTTP specifications
for more details on HTTP.
With the following lines added to the HTTP header, the deck will expire immediately:
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 |
|
The first line tells the micro browser that the deck should expire some time in the past.
The second line tells the browser when the deck was last modified, and "DD"
should be replaced by the current day-of-the-month (eg. "28"), "month"
with the current month (eg. "january"), "YYYY" with the current year
(eg. "1999"), "HH:MM:SS" with the current time (eg. (08:19:23").
The third and the fourth line have the same effect, ie. to tell the browser that the deck
should not be cached - line three is HTTP 1.1 and line four is HTTP 1.0.
The following PHP example produces the above header each time the deck is accessed.
|
<?
header("Content-type: text/vnd.wap.wml");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . "
GMT");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
?> |
// set the
correct MIME type
// expires in the past
// Last modified, right now
// Prevent caching, HTTP/1.1
// Prevent caching, HTTP/1.0 |
|
|
Here's an example using WebClasses in VB, using "-1" as
a value for Response.Expires to prevent caching.
|
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 |
|
And here's an example in ASP, again using "-1" as a value for Response.Expires
to prevent caching.
|
<%
Response.ContentType = "text/vnd.wap.wml"
Response.Expires = -1
Response.AddHeader "Pragma", "no-cache"
Response.AddHeader "Cache-Control", "no-cache, must-revalidate"
%> |
|
|
And finally a couple of examples on controlling the caching of static
decks using META tags:
The following deck will always be loaded off the server. Note that you should never
use this unless you know what you're doing since it eats bandwidth and "wastes"
time, every time the deck is requested. |
|
<?xml
version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"
"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> |
|
|
The following deck will be loaded instantly from the browser's cache
memory instead of from the server until 86400 seconds (24 hours) have passed. |
|
<?xml
version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"
"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> |
|
|
Some browsers such as the UP.Browser will not reload a deck if it
is reached by going "back" from another card. (The object of the cache is to save
bandwidth and time). To force this behaviour, you must use the must-revalidate
parameter to the META tag. |
<meta
forua="true" http-equiv="Cache-Control"
content="must-revalidate"/> |
|