WMS Layers Not Refreshing with Caching Disabled

3228
6
Jump to solution
07-08-2014 07:40 AM
CharlesGant
New Contributor III

All,

I have a series of WMS layers that I'm pulling in from NOAA's NowCoast.  All is well except when trying to refresh the layers.  I have the page setup to auto refresh, and also to refresh using an onClick button.  When I click the button (after waiting sufficient time for the image to be updated on the parent server), nothing happens.  However, as soon as I pan or zoom the map, it refreshes.  So did some searching and found an old thread that suggested including map.setExtent(map.extent) in the refresh function.  So I did this, which is what actually makes the map refresh on pan/zoom I believe, without that, it wouldn't even refresh on pan/zoom.  Thus, I am still not getting what I want.  Can anyone help me out?

function RefreshWMSLayers(){
wmsRadarLayer.refresh();
wmsWarnLayer.refresh();
wmsGOESVISLayer.refresh();
wmsGOESIRLayer.refresh();
wmsOBSLayer.refresh();
wmsTempLayer.refresh();
wmsSSTLayer.refresh();
}
function AutoRefreshMap(){
dts = getDateTime();
console.log("Auto Refreshing at " + dts);
document.getElementById('DTS').textContent = dts;
RefreshWMSLayers();
map.setExtent(map.extent);

function RefreshMap(){
dts = getDateTime();
console.log("On Demand Refreshing at " + dts);
document.getElementById('DTS').textContent = dts; 
RefreshWMSLayers();
map.setExtent(map.extent);

}
0 Kudos
1 Solution

Accepted Solutions
JasonGreenlaw
Occasional Contributor

Assuming you are using the WMSLayer class, you are likely running into a caching issue.

Essentially, your browser doesn't know the underlying image has changed, as the URL remains the same.  This is why panning or zooming gives you the latest image; by changing the extent of your WMS GetMap request, the URL changes, and since it does not exist in your browser cache yet, a new image is downloaded from the service.

According to the WMSLayer documentation, the refresh() function only works if the disableClientCaching property of the service is set to true.  Unfortunately the disableClientCaching property is not listed as a valid property of WMSLayer (it is listed under ArcGISDynamicMapServiceLayer, however), but I suspect it may still work.

Try the following:

wmsRadarLayer.disableClientCaching = true;

wmsRadarLayer.refresh();

If that doesn't work, try this:

wmsRadarLayer.setDisableClientCaching(true);

wmsRadarLayer.refresh();

If neither of those work, this option may not be supported for the WMSLayer class, and your only option (other than submitting an enhancement request) would likely be to create your own WMSLayer class whose getImageURL() function includes a random number (or perhaps the present epoch time) as an extra query parameter, such as "&nocache=1406055134".  You can find an example of creating a custom WMS Layer here:  Custom layer - WMS | ArcGIS API for JavaScript

View solution in original post

0 Kudos
6 Replies
JohnGravois
Frequent Contributor

perhaps try setting the refreshInterval property which was added at 3.7?

0 Kudos
CharlesGant
New Contributor III

Thanks for the help John.  However, the WMS Layer still only updates when I physically pan/zoom the map.  Here is the modification I made to the WMSLayer call.

   var layers = new WMSLayerInfo({});
   var resourceInfo = {extent: new Extent(-126.40869140625, 31.025390625, -109.66552734375, 41.5283203125, {wkid: 4326}),layerInfos: [layers]};
  
   var wmsRadarLayer = new WMSLayer('http://nowcoast.noaa.gov:80/wms/com.esri.wms.Esrimap/obs?', {resourceInfo: resourceInfo,visibleLayers: ['RAS_RIDGE_NEXRAD'],"visible":false,"setDisableClientCaching":true,"refreshInterval":1.0,opacity:0.9});
   wmsRadarLayer.version = "1.1.1";

0 Kudos
JohnGravois
Frequent Contributor

based on my reading of the doc, refreshInterval is property of the class that is not exposed as a constructor option. 

try setting it independently.

var wmsRadarLayer = new WMSLayer('http://...

//interval is defined in minutes (.05 = 3 seconds)

wmsRadarLayer.refreshInterval = .05;

0 Kudos
CharlesGant
New Contributor III

Well I tried that and it seems to still be only updating when I pan/zoom.  I copied in exactly what you have in the post above.  All I did was change the interval to 1 minute.  I sat and watched for ten minutes with no update.  As soon as I touched the map and panned just a bit, it updated.

wmsRadarLayer.refreshInterval = .05;

0 Kudos
CharlesGant
New Contributor III

Still looking for an answer.  Does anyone have any guidance on this issue they would like to share?  The maps update fine as long as I pan/zoom.  Otherwise, no update.  I need them to update automatically either on their own, or within a function like above. 

0 Kudos
JasonGreenlaw
Occasional Contributor

Assuming you are using the WMSLayer class, you are likely running into a caching issue.

Essentially, your browser doesn't know the underlying image has changed, as the URL remains the same.  This is why panning or zooming gives you the latest image; by changing the extent of your WMS GetMap request, the URL changes, and since it does not exist in your browser cache yet, a new image is downloaded from the service.

According to the WMSLayer documentation, the refresh() function only works if the disableClientCaching property of the service is set to true.  Unfortunately the disableClientCaching property is not listed as a valid property of WMSLayer (it is listed under ArcGISDynamicMapServiceLayer, however), but I suspect it may still work.

Try the following:

wmsRadarLayer.disableClientCaching = true;

wmsRadarLayer.refresh();

If that doesn't work, try this:

wmsRadarLayer.setDisableClientCaching(true);

wmsRadarLayer.refresh();

If neither of those work, this option may not be supported for the WMSLayer class, and your only option (other than submitting an enhancement request) would likely be to create your own WMSLayer class whose getImageURL() function includes a random number (or perhaps the present epoch time) as an extra query parameter, such as "&nocache=1406055134".  You can find an example of creating a custom WMS Layer here:  Custom layer - WMS | ArcGIS API for JavaScript

0 Kudos