[GIS] Prevent OpenLayers WMS layer cache by browser

geoserverjavascriptopenlayers-2wms

I am using OpenLayers (GeoExt) with google chrome browser. All WMS layer is for live database. I have refreshed the browser at certain interval using javascript but the data is cached in browser and when I refresh web page I see old data. When I clear cache from browser I see new data. How do I prevent caching or clear the cache automatically?

function RefreshPage(Period) {
    setTimeout("location.reload(true);", Period);
}

Best Answer

The trick of using the "myData" parameter should be unnessesarry, as we see in the OpenLayers.Layer.HTTPRequest (which the WMS layer inherits from):

redraw: function(force) { 
    if (force) {
        return this.mergeNewParams({"_olSalt": Math.random()});
    } else {
        return OpenLayers.Layer.prototype.redraw.apply(this, []);
    }
},

if you do layer.redraw(true); OpenLayers adds a random parameter for you

(besides, setting myData to Math.random() on initialization will not change myData for each update)