OUI

4.12 How can I control caching when nothing else works?

Please read this article before continuing. It's important to know when to use cache control, and when not to use it. After all, caching is there to speed up the navigation process.

In some rare cases normal cache control will not work either because browsers or gateways simply do not comply with HTTP specifications, or because your application work in such a way that normal cache control can not be applied.

For instance, at the time of writing, the UP.browser 4.x does not seem to handle normal HTTP cache control headers, and so called META control header must be used in the WML deck. The only problem is that when the content you are trying to control is not a WML deck but an image, META headers can obviously not used as an image has binary content.

There are two methods of tricking the browser into reload a URL, regardless of the cache. The first is by far the better solution, but it might not work on all browsers. I repeat that such cache bypassing schemes must only be used when all else fails!

has submitted the following method which involves adding a HTTP header called Content-location:. The method is known to work with the UP.browser series.

The following PHP code snippet will do just that, but any good server side script language can do the same.

<?
  header("Content-location: http://...");
?>

The browser will now think that the content is on the fake URL, and cache that URL instead of the real URL.

The second method is simply to add a random string to the URL, and although nasty, it will work on all browsers. Just remember that if you're already passing parameters on the URL, make sure that the URL still has a correct syntax and that it's not getting too long.

The following WML with a small PHP snippet example will do just this. The function date("U") returns the numbers of seconds since the Unix Epoc. I've used this method of creating a unique random number instead of a normal random routine because this ensures that the number is unique.

<card id="test">
 <p>The following URL will never be cached</p>
 <p><a href="http://...("?".date("U"))?>">Click here</a></p>
</card>

The URL in the code above will look like http://... where the number will change every time (that is, every second) the deck is loaded. The request parameter, everything after the question mark, will simply be ignored unless there's a script at that location which reads and parses the parameter.

[ Main ]   [ 04 - Serving WML contents ]