Unable to set Layer caching option programatically - ArcPro SDK 2.8

395
3
Jump to solution
09-13-2021 12:51 AM
PrashantKirpan
Occasional Contributor

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

 

Cache.PNG

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

 

 

0 Kudos
1 Solution

Accepted Solutions
CharlesMacleod
Esri Regular Contributor

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

View solution in original post

0 Kudos
3 Replies
Wolf
by Esri Regular Contributor
Esri Regular Contributor

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:

 

InSessionCache is maintained in session.
MaxAgeCache expires when it reaches the set maximum age.
NoneNo cache.
PermanentCache is permanent.

 

 

 

0 Kudos
PrashantKirpan
Occasional Contributor

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

0 Kudos
CharlesMacleod
Esri Regular Contributor

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

View solution in original post

0 Kudos