Disable client caching for a map service layer

1539
1
07-05-2016 08:32 AM
TrentonRawlinson1
New Contributor

I recently created a web app for road travel conditions using Web AppBuilder on ArcGIS Online, downloaded the code and hosted it on one of our servers. I am having a problem with cached data using a map service layer. Once you navigate back to an extent that you have previously been to a "304 Not Modified" is returned and cached data is displayed. Our road condition data changes frequently and I can't have old data displaying when someone goes back to an extent they have previously been to.

In the web map the refresh interval for this map service is not set. In other apps I have developed using the JavaScript API I can use the "setDisableClientCaching" parameter on the map service layer. Is there something similar that I can set in WAB? I tried setting it in the jimu.js/main.js with no luck.

Other layers in the app are brought into the web map as feature layers with refresh intervals set and they work great. The symbology being used for the road conditions is not supported as a feature layer so I am restricted to using a map service layer.

Any help is greatly appreciated.

0 Kudos
1 Reply
TrentonRawlinson1
New Contributor

If anyone else is having the same issue I found a workaround. I added some code in the "jimu/LayerInfos/LayerInfoFactory" function in the root/jimu.js/main.js file to disable client caching for the road conditions layer. Lines 30-33 below is what I added.

"jimu/LayerInfos/LayerInfoFactory": function() {
    define(["dojo/_base/declare",
        "dojo/_base/lang", "dojo/Deferred"
    ], function(m, e, h) {
        var k = null,
            d = m(null, {
                constructor: function() {},
                init: function() {
                    var d = new h;
                    require("jimu/LayerInfos/LayerInfoForCollection jimu/LayerInfos/LayerInfoForMapService jimu/LayerInfos/LayerInfoForKML jimu/LayerInfos/LayerInfoForGeoRSS jimu/LayerInfos/LayerInfoForDefault jimu/LayerInfos/LayerInfoForWMS jimu/LayerInfos/LayerInfoForGroup jimu/LayerInfos/LayerInfoForDefaultDynamic jimu/LayerInfos/LayerInfoForDefaultTile jimu/LayerInfos/LayerInfoForDefaultWMS jimu/LayerInfos/LayerInfoForDefaultTable jimu/LayerInfos/LayerInfoForDefaultImage jimu/LayerInfos/LayerInfoForDefaultStream".split(" "),
                        e.hitch(this, function(e, c, g, a, s, r, q, f, p, h, b, k, u) {
                            this.LayerInfoForCollection = e;
                            this.LayerInfoForMapService = c;
                            this.LayerInfoForKML = g;
                            this.LayerInfoForGeoRSS = a;
                            this.LayerInfoForDefault = s;
                            this.LayerInfoForWMS = r;
                            this.LayerInfoForGroup = q;
                            this.LayerInfoForDefaultDynamic = f;
                            this.LayerInfoForDefaultTile = p;
                            this.LayerInfoForDefaultWMS = h;
                            this.LayerInfoForDefaultTable = b;
                            this.LayerInfoForDefaultImage = k;
                            this.LayerInfoForDefaultStream = u;
                            d.resolve()
                        }));
                    return d
                },
                create: function(d) {
                    /*---disable client caching for road conditions---*/
                    if (d.id === "Road_Conditions_4274") {
                        d.layerObject.disableClientCaching = !0;
                    }
                    if (d.featureCollection) return new this.LayerInfoForCollection(d,
                        this.map);
                    if ("esri.layers.KMLLayer" === d.layerObject.declaredClass) return new this.LayerInfoForKML(d, this.map);
                    if ("esri.layers.GeoRSSLayer" === d.layerObject.declaredClass) return new this.LayerInfoForGeoRSS(d, this.map);
                    if ("esri.layers.WMSLayer" === d.layerObject.declaredClass && !d.selfType) return new this.LayerInfoForWMS(d, this.map);
                    if ("esri.layers.ArcGISDynamicMapServiceLayer" === d.layerObject.declaredClass || "esri.layers.ArcGISTiledMapServiceLayer" === d.layerObject.declaredClass) return new this.LayerInfoForMapService(d, this.map);
                    if ("esri.layers.ArcGISImageServiceLayer" === d.layerObject.declaredClass || "esri.layers.ArcGISImageServiceVectorLayer" === d.layerObject.declaredClass) return new this.LayerInfoForDefaultImage(d, this.map);
                    if ("esri.layers.StreamLayer" === d.layerObject.declaredClass) return new this.LayerInfoForDefaultStream(d, this.map);
                    "Table" === d.layerObject.type && (d.selfType = "table");
                    switch (d.selfType) {
                        case "mapservice_dynamic_group":
                            return new this.LayerInfoForGroup(d, this.map);
                        case "mapservice_tiled_group":
                            return new this.LayerInfoForGroup(d, this.map, !0);
                        case "mapservice_dynamic":
                            return new this.LayerInfoForDefaultDynamic(d, this.map);
                        case "mapservice_tiled":
                            return new this.LayerInfoForDefaultTile(d, this.map);
                        case "wms":
                            return new this.LayerInfoForDefaultWMS(d, this.map);
                        case "table":
                            return new this.LayerInfoForDefaultTable(d, this.map);
                        default:
                            return new this.LayerInfoForDefault(d, this.map)
                    }
                }
            });
        d.getInstance = function(e) {
            null === k && (k = new d);
            e && (k.map = e);
            return k
        };
        return d
    })
},