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);
}
Answer
If I remember correctly, you can insert your own parameter into the WMS layer configuration:
var wms = new OpenLayers.Layer.WMS("NASA Global Mosaic",
"http://wms.jpl.nasa.gov/wms.cgi",
{
layers: "modis,global_mosaic",
transparent: true,
myData: Math.random()
}, {
opacity: 0.5,
singleTile: true
});
You can use the current time or another random value. The key myData
will be URL encoded into the request sent to the WMS provider and the request is now changed due to the new value of myData
.
This doesn't clear the cache, but it tells the browser that the request is different from the one it previously cached.
If you just want to refresh your WMS layers, this can be done by
myWMSLayer.redraw(true);
The parameter true
tells the layer to force a redraw.
No comments:
Post a Comment