In this topic
Caching in dynamic display
Dynamic display can reuse the cache for nondynamic layers. The cache structure for dynamic display is similar to the ArcGIS Server cache structure. Cache information for a nondynamic 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:
- Save layers as layer files (.lyr) or save maps as map files (.mxd)
- Programmatically generate or update caches, then save layers as layer files or save maps as map files
- Programmatically connect layers to an existing cache with IDynamicCacheLayerManager, then save layers as layer files or save maps as map files
Saving layers as layer files or saving maps as map files
Save layers as layer files or save maps as map files when dynamic display is enabled. Enable the dynamic map first, then save the layers as layer files or save the maps as map files to reuse the existing cache information during the navigation.
Layer files and map files persist cache information when saved while in dynamic mode. To persist the cache, save a .mxd or .lyr file with dynamic display enabled. The next time dynamic display is enabled on the same or different session, it identifies the existing cache, then uses it.
Cache information is not based on one map scale, but a range of map scales. Once an area in the map is accessed (zooming and roaming), the cache information generates for that area (on a background thread). When you revisit the same area, dynamic display knows where the cache is and reuses that cache for the nondynamic layers.
If you know the area and map scale you will access during a session of your mapping application, you can precook caches by zooming in and roaming to the applicable area, then save the .mxd file (do this while in dynamic mode). The caches will be reused without having to use any CPU when you perform the navigation on the same map in consequent sessions.
Generating or updating caches
Programmatically generate or update caches, then save layers as layer files or save maps as map files. As previously mentioned, cache information for nondynamic layers can be generated automatically when dynamic display is enabled. It can also be generated programmatically by the IDynamicCacheLayerManager.Update method. Either way, by default, cache information is saved to the temp directory in the user profile. However, with IDynamicCacheLayerManager, you cannot only define your cache directory, but also generate or update the cache information in both dynamic mode and nondynamic mode.
The IDynamicCacheLayerManager.Update method has the following three esriMapCacheUpdateMode options for the update mode:
- With the esriMapCacheUpdateRecreateAll mode, you can either pre-generate the entire cache from scratch, then save the layers as layer files or save the maps as map files, or you can replace the entire existing cache associated with the existing layer files or map files
- With the 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 the esriMapCacheUpdateDelete mode, all tiles associated with the layer files or map files will be removed.
Initialize the cache manager with the map and layer to use 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 scratch or replacing the entire existing cache. It is assumed that you have a valid Map control.
IMap map = axMapControl1.Map;
IDynamicCacheLayerManager dynamicCacheLayerManager = new
DynamicCacheLayerManagerClass();
ILayer layer = map.get_Layer(0);
if (layer is IDynamicLayer)
{
return ;
}
dynamicCacheLayerManager.Init(map, layer);
dynamicCacheLayerManager.Update(layer.AreaOfInterest, 0, m_map.MapScale,
esriMapCacheUpdateMode.esriMapCacheUpdateRecreateMissing);
[VB.NET]
Dim map As IMap = axMapControl1.Map
Dim dynamicCacheLayerManager As IDynamicCacheLayerManager = New DynamicCacheLayerManagerClass()
Dim layer As ILayer = map.Layer(0)
If TypeOf layer Is IDynamicLayer Then
Return
End If
dynamicCacheLayerManager.Init (map, layer)
dynamicCacheLayerManager.Update (layer.AreaOfInterest, 0, m_map.MapScale, esriMapCacheUpdateMode.esriMapCacheUpdateRecreateMissing);
Remember, that the IDynamicCacheLayerManager.Update method is based on per layer rather than per map. To update existing caches, load the associated layer files or map files. After updating or generating the caches, save the layers as layer files or save the maps as map files to persist the cache information.
Connecting layers to existing caches
Programmatically connect layers to existing caches, then save layers as layer files or save maps as map files. Additionally, 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 location through 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.FolderName. See the following code example:
[C#]
// It is assumed that the cache information has been moved to the Connect folder on the C drive.
string sConnectFolderPath = @"C:\Connect”;
IMap map = axMapControl1.Map;
IDynamicCacheLayerManager dynamicCacheLayerManager = new
DynamicCacheLayerManagerClass();
ILayer layer = map.get_Layer(0);
if (layer is IDynamicLayer)
{
return ;
}
dynamicCacheLayerManager.Init(map, layer);
string sCacheFolderName = dynamicCacheLayerManager.FolderName;
dynamicCacheLayerManager.Connect(sConnectFolderPath, sCacheFolderName);
[VB.NET]
' It is assumed that the cache information has been moved to the Connect folder on the C drive.
Dim sConnectFolderPath As String = "C:\Connect”
Dim map As IMap = axMapControl1.Map
Dim dynamicCacheLayerManager As IDynamicCacheLayerManager = New DynamicCacheLayerManagerClass()
Dim layer As ILayer = map.Layer(0)
If TypeOf layer Is IDynamicLayer Then
Return
End If
dynamicCacheLayerManager.Init (map, layer)
Dim sCacheFolderName As String = dynamicCacheLayerManager.FolderName
dynamicCacheLayerManager.Connect (sConnectFolderPath, sCacheFolderName)
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.
Remember, 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 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:
Dynamic displayHow dynamic display works
Controlling drawing characteristics of nondynamic layers using IDynamicCacheLayerManager
Maximizing performance in dynamic display
Development licensing | Deployment licensing |
---|---|
Engine Developer Kit | Engine Runtime |
ArcView | |
ArcEditor | |
ArcInfo |