Best Practices for cache information for static layers in base maps


Summary Layers that don’t implement the interface IDynamicLayer are regarded as non-dynamic layers. This document discusses how to manage the caching properties of non-dynamic layers by using IDynamicCacheLayerManager Interface for best performance.

In this topic


Caching in dynamic display

Dynamic display can reuse the cache for non-dynamic layers. The cache structure for dynamic display is similar to the ArcGIS Server cache structure. Cache information for a non-dynamic layer is generated by a background thread. During navigation, if the cache is unavailable for that area, the background thread tries to create it, which leads to central processing unit (CPU) usage. To improve performance, the following are the options to persist the cache information in dynamic display using IDynamicCacheLayerManager interface:
  • Programmatically generate or update caches, then save layers as layer files or save maps as map files
  • Programmatically connect layers to an existing cache, then save layers as layer files or save maps as map files
Programmatically generate or update caches
The cache information for non dynamic layers can be generated automatically when dynamic display is enabled. It can also be generated programmatically by IDynamicCacheLayerManager.update method. By default, cache information is saved to the temp directory of the user profile. However, with IDynamicCacheLayerManager, you can define your cache directory and also generate or update the cache information in both dynamic mode and nondynamic mode. The IDynamicCacheLayerManager.update method has three update modes.
  • With esriMapCacheUpdateRecreateAll mode, you can either pre-generate the entire cache from the scratch, then save the layers as layer files or save the maps as map files, or you canreplace the entire existing cache associated with the existing layer files or map files;
  •  With esriMapCacheUpdateRecreateMissing mode, you can create the missing tiles associated with the existing layer files or map files. In this way, new tiles will be added into the existing cache when the layer extent has changed or the range of map scale has alternated;
  • With esriMapCacheUpdateDeletemode, all tiles associated with the layer files or map files will be removed.
The cache manager should be initialized for all layers using IDynamicCacheLayerManager.init() method prior to using the methods and properties on IDynamicCacheLayerManager.
The following code example shows how to update the cache associated with the given layer within the entire layer’s area of interest, for all scales up to the current map scale, pre-generating the entire cache from the scratch or replacing the entire existing cache. It assumes that you already have a valid map object:
[Java]
IMap map = ...;
String cacheFolder = "C:/myCache";
IDynamicCacheLayerManager dynamicCacheLayerManager = new DynamicCacheLayerManager();
ILayer layer = map.getLayer(0);
if (layer instanceof IDynamicLayer)
    return ;
dynamicCacheLayerManager.init(map, layer);
dynamicCacheLayerManager.update(layer.getAreaOfInterest(), 0, map.getMapScale(),
    esriMapCacheUpdateMode.esriMapCacheUpdateRecreateMissing);
Keep in mind that IDynamicCacheLayerManager.update method is based on per layer rather than per map. In order to update the existing caches, you must load associated layer files or map files. After updating or generating the caches, you must save the layers as layer files or save the maps as map files in order to persist the cache information.
Programmatically connect layers to existing caches
In addition, cache information can be moved or copied to different locations. A connection can then be made between the layer and the existing cache in the new locationthrough the IDynamicCacheLayerManager.connect method. The cache information can be reused on the same machine or on a different machine as long as the data location (path) is not changed.
To connect to an existing cache and initialize the cache manager with the map and layer, the folder name must be known. The folder name is composed of the layer name with a globally unique identifier (GUID) assigned by the dynamic display. You can get the folder name from IDynamicCacheLayerManager.getCacheFolder() method. See the following code example:
The IDynamicCacheLayerManager.connect() method
[Java]

String cacheFolderPath = "C:/Connect”;

IMap map = axMapControl1.Map;
IDynamicCacheLayerManager dynamicCacheLayerManager = new DynamicCacheLayerManager();
ILayer layer = map.getLayer(0);
if (layer instanceof IDynamicLayer){
    return ;
}

dynamicCacheLayerManager.init(map, layer);
string cacheFolderName = dynamicCacheLayerManager.getFolderName();
dynamicCacheLayerManager.connect(cacheFolderPath, cacheFolderName);
The Connect method checks the following conditions before making a connection to the cache:
  • The cache structure matches the input layer.
  • Spatial reference of the target cache matches the map's spatial reference.
  • The compression format of the cache matches the compression set for the layer.
  • If the input layer has a reference scale, it matches the reference scale set to the cache.
  • Renderers and labels are identical.
Keep in mind that you still need to save layers as layer files or save maps as map files after the cache is connected to the associated layer in order to persist the cache information.
In conclusion, cache information can be reused in dynamic display to improve the performance. A cache can be generated ahead of time by enabling dynamic mode or using IDynamicCacheLayerManager, be persisted with .lyr or .mxd files, and be relocated to make a connection between the cache and the layer.


See Also:

About dynamic display
How dynamic display works
Rendering non-dynamic layers
Controlling drawing characteristics of non-dynamic layers using IDynamicCacheLayerManager




Development licensing Deployment licensing
Engine Developer Kit Engine Runtime
ArcView
ArcEditor
ArcInfo