I'm using the following code to open a connection to a feature server and adding a feature layer to the current map:
var serviceUrl = @"http://url-of-feature-server/FeatureServer";
var layerId = "0";
var map = MapView.Active.Map;
using (var geoDb = new Geodatabase(new ServiceConnectionProperties(new Uri(serviceUrl)))
{
var defNames = geoDb.GetDefinitions<FeatureClassDefinition>()
.Select(def => def.GetName()).ToArray();
var id = int.Parse(layerId);
Debug.Assert(defNames.Length > id);
if (defNames.Length > id)
{
using (var featureClass = geoDb.OpenDataset<FeatureClass>(defNames[id]))
{
featureLayer = LayerFactory.Instance.CreateFeatureLayer(featureClass, map);
featureLayer.SetDisplayCacheType(DisplayCacheType.None);
featureLayer.SetDisplayCacheMaxAge(TimeSpan.Zero);
}
}
}
This works fine the 1st time this code gets executed. If the feature server has N feature layers then defNames gets N definitions.
If the feature server gains a new layer, one would expect that the next time this code gets executed defNames would have N + 1 items. However it still returns N definitions. Using Fiddler, I can see that ArcGIS performs HTTP requests (to get feature definitions, metadata, etc.) the 1st time the Geodatabase object is created. Subsequent creations of new Geodatabase objects (using the same service URL) does not make any other HTTP requests, even when geoDb object was disposed via "using", as if it was being cached by ArcGIS.
I would like to ensure that every time I create a new Geodatabase object that it has the most recent feature definitions and ArcGIS doesn't cache anything. How would one do that?
Additionally, I've noticed that SetDisplayCacheType(DisplayCacheType.None) does not seem to apply or update the layer's properties (checking via Layer->Properties->Cache).
Thanks Mark. We've added this as an issue for our next release after 2.2.
Thanks Charles. Do you have any recommendations for work arounds in the meantime? Is there any way to force Pro to refresh the available layers in a service? Are there any flags that we could set in the service/layer metadata?
Hi James, unfortunately, there is no workaround.
Hey Charles. I'm just checking up on this to see if you have any update on a fix for this.
Thanks,
-James
James,
This will be fixed in Pro 2.3, expected early 2019.
--Rich
Thanks Rich.
When the cache type is set in code, is the Cache property tab supposed to update? When I set cache type to None (or any other value), the UI has "Clear cache when the session ends" selected. Also, ArcGIS Pro doesn't seem to use the value set via code, instead it's using the value seen in the UI.
ArcGIS Pro 2.7.3 is being used.
featureLayer.SetDisplayCacheType(ArcGIS.Core.CIM.DisplayCacheType.None);