Adding a feature layer via Geodatabase

783
7
05-15-2018 09:43 AM
MarkGumban
New Contributor

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).

0 Kudos
7 Replies
CharlesMacleod
Esri Regular Contributor

Thanks Mark. We've added this as an issue for our next release after 2.2.

0 Kudos
JamesKerr
New Contributor

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?

0 Kudos
CharlesMacleod
Esri Regular Contributor

Hi James, unfortunately, there is no workaround.

0 Kudos
JamesKerr
New Contributor

Hey Charles. I'm just checking up on this to see if you have any update on a fix for this.

Thanks,

-James

0 Kudos
RichRuh
Esri Regular Contributor

James,

This will be fixed in Pro 2.3, expected early 2019.

--Rich

0 Kudos
JamesKerr
New Contributor

Thanks Rich.

0 Kudos
JeffRogholt
New Contributor II

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);

2021-09-13_10-50-08.jpg

0 Kudos