Hi All,
I'm adding feature service to map using ArcPro SDK 2.8. I've observed that that by default 'Clear Cache when session End' option is selected for each layer. Due to this option my data is not displaying properly on map. I tried to turn layer on/off manually or zoom in/out couple if times but still issue remains same.
I don't want to cache any data locally so I used below code to set cache option but UI doesn't change and still 'Clear Cahce..' is selected.
var featureLayer = MapView.Active.Map.GetLayersAsFlattenedList().OfType<FeatureLayer>().FirstOrDefault();
featureLayer.SetDisplayCacheType(DisplayCacheType.None);
In SDK 2.7 by default last option 'Don't cache any data locally' was selected so didn't face any issue while displaying data but in 2.8 behavior has changed.
Any idea how to set option 'Don't cache any data locally' from add-in?
-Prashant
Solved! Go to Solution.
Prashant, looks like it is a bug. We will try and get this fixed in 2.9.
Meanwhile, please try the following workaround (which sets the underlying FeatureCacheType manually):
internal class DisplayCache : Button
{
protected async override void OnClick()
{
var fl = MapView.Active.Map.GetLayersAsFlattenedList()
.OfType<FeatureLayer>().FirstOrDefault();
if (fl == null)
return;
await QueuedTask.Run(() =>
{
if (fl.GetIsFeatureServiceLayer())
{
var def = fl.GetDefinition() as CIMFeatureLayer;
def.DisplayCacheType = DisplayCacheType.None;
def.FeatureCacheType = FeatureCacheType.None;
fl.SetDefinition(def);
}
});
}
}
internal static class FeatureServiceLayerExtensions
{
public static bool GetIsFeatureServiceLayer(this FeatureLayer flayer)
{
if (flayer.ConnectionStatus == ConnectionStatus.Broken)
return false;
GeodatabaseType gdbType = GeodatabaseType.FileSystem;
using (var dataset = flayer.GetTable())
{
using (var gdb = dataset.GetDatastore())
{
//Note shapefile will be "FileSystemDatastore"
if (gdb is Geodatabase)
{
gdbType = ((Geodatabase)gdb).GetGeodatabaseType();
}
}
}
return gdbType == GeodatabaseType.Service;
}
}
You can use the following method of the Layer class to change the DisplayCache settings:
SetDisplayCacheType (DisplayCacheType cacheType)
ArcGIS Pro 2.8 API Reference Guide - Layer Class Members—ArcGIS Pro
DisplayCacheType (ArcGIS Pro 2.8 API Reference Guide - DisplayCacheType Enumeration—ArcGIS Pro )
allows the following options:
InSession | Cache is maintained in session. |
MaxAge | Cache expires when it reaches the set maximum age. |
None | No cache. |
Permanent | Cache is permanent. |
Yes, I'm using same layer class to change settings but no changes in UI. Here is my code
var featureLayer = MapView.Active.Map.GetLayersAsFlattenedList().OfType<FeatureLayer>().FirstOrDefault();
featureLayer.SetDisplayCacheType(DisplayCacheType.None);
-Prashant
Prashant, looks like it is a bug. We will try and get this fixed in 2.9.
Meanwhile, please try the following workaround (which sets the underlying FeatureCacheType manually):
internal class DisplayCache : Button
{
protected async override void OnClick()
{
var fl = MapView.Active.Map.GetLayersAsFlattenedList()
.OfType<FeatureLayer>().FirstOrDefault();
if (fl == null)
return;
await QueuedTask.Run(() =>
{
if (fl.GetIsFeatureServiceLayer())
{
var def = fl.GetDefinition() as CIMFeatureLayer;
def.DisplayCacheType = DisplayCacheType.None;
def.FeatureCacheType = FeatureCacheType.None;
fl.SetDefinition(def);
}
});
}
}
internal static class FeatureServiceLayerExtensions
{
public static bool GetIsFeatureServiceLayer(this FeatureLayer flayer)
{
if (flayer.ConnectionStatus == ConnectionStatus.Broken)
return false;
GeodatabaseType gdbType = GeodatabaseType.FileSystem;
using (var dataset = flayer.GetTable())
{
using (var gdb = dataset.GetDatastore())
{
//Note shapefile will be "FileSystemDatastore"
if (gdb is Geodatabase)
{
gdbType = ((Geodatabase)gdb).GetGeodatabaseType();
}
}
}
return gdbType == GeodatabaseType.Service;
}
}