Tutorial: Creating a cached map service

Complexity: Intermediate Data Requirement: Use your own data

The best way to create fast map services is to cache them. When you cache a map service, the server draws the map at a set of scale levels that you define and saves the images. When the server receives a request for a map, it's much quicker to return one of these cached images than to draw the map again.

Caching is appropriate for basemaps and maps that don't change often. For maps that change only occasionally, tools are available to update the cache. To achieve optimal performance, you should cache as many layers as you can. You may find it helpful to make two maps and separate the layers that are appropriate for caching from layers that would not be feasible to cache. For example, you could create a cached map service from the basemap layers and a noncached map service from layers that get updated in real time or layers that change as a result of analysis or modeling.

Creating an effective map cache requires you to do some careful design and authoring work before you build the cache. This tutorial walks you through the process of planning and authoring a map that will be cached. You'll then create a map service and cache it. Finally, you'll test the cache in several client applications.

When working on this tutorial, select some simple datasets that cover a fairly small area, such as a city or county. This tutorial is meant as a practice so that you can prepare for future caching jobs within your organization. Pay close attention to the discussion and instructions, but don't worry about getting it perfect the first time. Designing good caches takes some practice.

This tutorial has four main sections:

Authoring the map

When you cache a map, the server draws it at a set of scales that you select. Once the map is drawn, you can't change the way it looks unless you re-create or update the cache. This means two important things:

Your organization may have already determined a tiling scheme to use when caching. A tiling scheme determines certain properties of your cache, including which scale levels to create.

Choosing your scales

In this tutorial, it is assumed that you are creating your own tiling scheme and you need to pick out some scales. To get started determining appropriate scales for your map, follow the steps below:

  1. Open a map document and add your datasets. Set some initial symbology to make the map look nice, but don't get too detailed at this point. Save the map.
  2. Now just take a few minutes to navigate the data. Pan and zoom around the areas that your users will view most often. As you navigate, mentally note the scales that you are viewing.
  3. Zoom in to the closest scale you think your users will need to view this map. Round this scale off a bit and write it down.
  4. Take the scale you are currently viewing and divide it by two (remember that the scale is really a fraction, so dividing it by two doubles the denominator). For example, if you are viewing 1:40,000, zoom to 1:80,000. The easiest way to do this is to type the scale directly into the scale drop-down list. Write down the new scale and briefly examine the map.
  5. Continue dividing the scale by two and writing down the scale until you reach a point where your users would not need to zoom out any farther. You now have your list of scales.

Note: It's not required that you divide the scale by two; you can use other numbers. But in most cases, dividing by two provides a good magnitude of zoom.

Setting up ArcMap to work with your scales

Now that you've chosen some scales, you can start making the map look good at each one. As you author the map, you may often need to move back and forth between these scales. To make this easier, you can enter the scales into the drop-down list in ArcMap:

  1. Click the drop-down list of scales in ArcMap.
  2. Click Customize this list.
    Screen shot of scale list
  3. If you only want your scales to appear in the list, click Delete All.
  4. Type one of your scales in the box and click Add. Keep doing this until you've added all your scales and click OK.
    Screen shot of Scale Settings dialog box

Making the map

Now it's time to do the real map design work. One benefit of caching your map is that during the design phase, you can use all the cartographic tools at your disposal without worrying about how they will affect performance. Take some time to make your map look nice, because once the cache is created, you will not be able to make changes without re-creating or updating the cache. Users of the cache won't be able to change the symbology either, since they're just viewing preexisting images of the map that are stored on the server.

A good practice is to design your map at each scale you've chosen for your cache. This is easier for raster data because ArcMap does some resampling of the data as you change scales. Vector data, however, will be symbolized with the same size points and lines at each scale and requires a little more effort to keep the map from looking too cluttered or too sparse. The steps below describe a design strategy you can use if your map contains vector data.

  1. With your map open in ArcMap, zoom out to the farthest (smallest) scale.
  2. Set the symbology and labeling of your layers for this scale.

    Tip: You may want to set a definition query so that fewer features are visible at this scale. For example, if you have a cities layer, you can set a definition query that limits display to cities with a population greater than 20,000.

    Screen shot of Query Builder dialog box located under the Definition Query tab of the Layer Properties dialog box
  3. Zoom in to the next closest scale.
  4. Set the symbology and labeling of your layers for this scale.

    Tip: If you want to change the symbology, labeling, or definition query on a layer that you already symbolized at a different scale, add another copy of the layer to the map. To do this, right-click the layer in the ArcMap table of contents and click Copy. Then right-click the data frame name and click Paste Layer(s).

    If you wind up with many copies of a layer, you can use a group layer to keep track of them. It's easiest to make one group layer for each scale. That way, you only have to set the scale dependency on the group instead of on each individual layer. You might even include the scale in the name. For example, you might have this group layer hierarchy:

    Screen shot of group layer hierarchy in the table of contents

    You need to set a scale range on each layer so that only one is visible at each cached scale. Configure the scale range with a tolerance around each cache scale. For example, with the roads layer pictured above that will be cached at 1:1,500,000, you might set the layer to be visible only when zoomed out beyond 1:1,000,000 and zoomed in beyond 1:2,000,000.

  5. Continue zooming to each successive scale and symbolizing appropriately until you've worked through all the scales in your list.
  6. Save your map and close ArcMap. You're ready to publish the map.

Publishing the map service

To create the cache, you must first publish your map as a service. You can use either ArcGIS Server Manager or the Catalog window. These instructions will use the Catalog window, since you'll be using it to create the cache anyway. Additionally, the ability to launch the caching tools is only available in ArcGIS Desktop.

In both Manager and ArcCatalog, there are two ways to create a service. The Publish GIS Resource wizard prompts you for the minimum amount of information needed to get the service up and running. It sets default values for all the other service properties. In contrast, the Add New Service wizard allows you to set advanced properties before you publish the service. These instructions show how to use the Add New Service wizard so that you can increase the default number of running instances. This greater number of instances will be able to use more processor resources when you create the cache.

  1. Open ArcCatalog and make an administrative connection to your GIS server. See Making an administrative connection to ArcGIS Server in ArcCatalog if you need help with this step.
  2. Right-click the connection and click Add New Service.
  3. Type a Name for the service and click Next.
  4. Fill in the Map Document text box by browsing to the map document you created. The ArcGIS Server Object Container (SOC) account needs permissions to read this document and any data it references.
  5. Use the Server Cache Directory drop-down list to choose the directory where you want your cache to be created. If the list is blank, you need to add a server cache directory before you can continue. See Creating a server directory for help.
  6. When you've chosen your server cache directory, click Next. Click Next again to choose the default capabilities for the service.
  7. Now you're on the page of the wizard where you can choose the pooling model and number of instances for the service. For cached services, you should always choose the default of Pooled. However, you can raise or lower the maximum number of instances to a number greater than 2.

    In most cases, a CPU can handle at least 3 instances while caching. More powerful machines, or configurations with multiple SOC machines, can handle even more instances. If you want to use all your server power in creating the cache or if you have a very large ArcGIS Server deployment, you should raise the default maximum number of instances.

    Screen shot of the Pooling tab of the Add ArcGIS Service wizard

    You may wonder if you need to increase the default time-out value to something greater than the default, since creating the cache can take a long time. Actually, the caching tools reset the time-out value to be very large before they start creating tiles, so you do not need to change the default time-out value here.

  8. After changing the maximum number of instances, click Next, then click Next again to keep accepting the defaults throughout the wizard. On the final page, choose Yes, start the service right now, then click Finish to create the service.
  9. In ArcCatalog, use the Preview tab to verify that the service appears as expected.

Creating the cache

Now that you have a running map service, you can create the cache. To get the caching started, follow these steps:

  1. In ArcCatalog or the Catalog window in ArcMap, find your service in the Catalog tree. Right-click the service and click Service Properties.
  2. Click the Caching tab. Here is where you can access some of the cache properties. You will use this tab to configure the tiling scheme before you start creating cache tiles.
  3. Choose to draw the map service Using tiles from a cache that you will define below.
  4. Type one of your scales in the Scales text box, then click Add. You should see the scale appear in the list.
  5. Continue entering scales and clicking Add for each one until you have reached the end of your list.
  6. Change the cache Tile Format to JPEG. This format produces small tiles and will reduce the disk space needed to store the cache. Clients can also load the tiles quicker.
    Screen shot of the Caching tab located on the Map Service Properties dialog box

    Note: This step assumes that you are not going to overlay this cache on another service. For overlay services, such as road and boundary networks, you should choose PNG8 or PNG32 instead. Use PNG32 if your overlay service has over 256 colors.

  7. You've now configured your tiling scheme (you'll use the defaults for all other properties). It's time to start creating tiles. Click Create Tiles.
  8. The Manage Map Server Cache Tiles tool appears with much of the required information already filled in. This is the tool you will use to create tiles. Take a moment to examine the tool's parameters.
  9. Change the Update Mode setting to Recreate All Tiles. You'll use this setting most often for creating and updating your caches.
  10. Optionally, change the Number of MapServer Instances setting. This number is a measure of the server computing power you want to dedicate toward creating your cache.
    Screen shot highlighting the Update Mode setting within the Manage Map Server Cache Tiles tool

    See Allocation of server resources to creating a map cache to learn more about this setting.

  11. You've filled in the essential properties for the tool, so click OK to begin generating the cache.

Depending on your largest scale, the extent of your data, and other factors, the cache can take some time to generate. If you picked some simple datasets with a small geographic extent for this exercise, the cache will probably be completed in less than an hour. The geoprocessing status window shows a progress bar of how much of your cache has been completed.

Testing the cache

Once the cache is finished, you can test it in a Web Mapping Application to make sure that the map appears and performs the way you expect. This is also a good way to verify that the tiles are being recognized and used successfully by the application.

The Web application you use for testing can be a simple one. A good way to create the test application is to use ArcGIS Server Manager.

  1. Click the Home tab of Manager and click Create a Web application.
  2. Type a Name for your Web application and optionally enter a Description. Then click Next.
  3. On this panel, click Add Layer. Then browse to your cached map service and add it to the map. If you need help with this step, see Adding layers to a Web application in Manager.
  4. You've completed the most important part of the wizard. Click Finish to accept the defaults for the other application settings.
  5. The completed Web application will appear in a new window. The levels in the zoom-level slider correspond to the scales in your cache.
    Screen shot of zoom-level slider
  6. Pan around the map and zoom to the different levels. When panning and zooming in the map, you should see the map tiles appear very quickly.


If it doesn't appear that the application is using the cache, make sure that

  • Your service pack levels match (if you have service packs applied).
  • You created a fused cache instead of a multilayer cache. The default is fused, and these instructions, if followed exactly, will create a fused cache.
  • The SOC account has Read and Write permissions to your server cache directory.

If you're using Mozilla Firefox to view your Web application, there's an easy way to tell if your cache tiles are being used.

  1. Click Tools and click Page Info.
  2. Click the Media tab.
  3. Examine the images that appear in the list. If you see images from your server cache directory (or its associated virtual directory), you know your cache is being used.
    Screen shot of the Media tab located on the Page Info dialog box in Mozilla Firefox

Further reading