ArcGIS Pro 3.2 API Reference Guide
ArcGIS.Desktop.Mapping Namespace / Layer Class / SetCacheOptions Method
The cache type.
Example

In This Topic
    SetCacheOptions Method
    In This Topic
    Sets the layer's caching options. If the layer's feature class supports feature caching, then both the display cache and feature cache are set otherwise just the display cache is set. This method must be called on the MCT. Use QueuedTask.Run
    Syntax
    public void SetCacheOptions( 
       LayerCacheType cacheType
    )
    Public Sub SetCacheOptions( _
       ByVal cacheType As LayerCacheType _
    ) 

    Parameters

    cacheType
    The cache type.
    Exceptions
    ExceptionDescription
    This method or property must be called within the lambda passed to QueuedTask.Run.
    Remarks
    The caching options are as follows
    • None - Don't cache the layer locally. If the layer supports feature caching (i.e. is a feature service layer), then any existing cache is also cleared.
    • Session - Cache will be cleared when the session ends.
    • MaxAge - Cache will be kept between sessions and cleared every MaxDisplayCacheAge minutes. If the layer supports feature caching (i.e. is a feature service layer), then this caching option is not supported and no changes are made.
    • Permanent - Cache will be kept between sessions and invalidated when the data is updated. If the layer supports feature caching (i.e. is a feature service layer), then this caching option is not supported and no changes are made.

    Refer to the Pro help for more information on caching: How caching works.
    Note: for feature services only ArcGIS.Core.CIM.DisplayCacheType.InSession and ArcGIS.Core.CIM.DisplayCacheType.None are supported. For branch versioned feature services, caching is managed by the application automatically and is set to DisplayCacheType.InSession.
    Attempting to set a cache type on a layer that is not supported is ignored. Note: If setting LayerCacheType.MaxAge, call SetDisplayCacheMaxAge to set the duration otherwise it uses the default value that is 5.0 minutes.

    Example
    Set the layer cache
    var featureLayer = MapView.Active.Map.GetLayersAsFlattenedList().OfType<FeatureLayer>().FirstOrDefault();
    ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
    {
      // change the layer cache type to maximum age
      //At 2.x - featureLayer.SetDisplayCacheType(ArcGIS.Core.CIM.DisplayCacheType.MaxAge);
      featureLayer.SetCacheOptions(LayerCacheType.MaxAge);
      // change from the default 5 min to 2 min
      featureLayer.SetDisplayCacheMaxAge(TimeSpan.FromMinutes(2));
    });
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also