Tutorial: Creating a cached map service

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 then saves the images. When the server receives a request for map, it’s much quicker to return one of these cached images than to draw the map again.

Caching is appropriate for base maps 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, such as base map layers, from layers that would not be feasible to cache, such as 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, we’ll assume 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 viewing right now and divide it by two (remember that the scale is really a fraction, so dividing it by two results in a larger number for the scale factor). 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 dropdown. 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 could 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 dropdown list in ArcMap:

  1. In ArcMap, click the dropdown list of scales.
  2. Click <Customize this list>

    Dropdown list of scales in ArcMap
  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 of your scales. Then click OK.

    Add your scale levels to the custom list

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 of 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 pre-existing 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 to the farthest out (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 may set a definition query that limits display to cities with a population greater than 20,000.

    Setting a definition query
  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. Enter names for the group layer that are easy to remember. You might even include the scale in the name. For example, you might have this group layer hierarchy:

    Group layer containing separate symbologies for each scale

    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:8000, you might set the layer to be visible only when zoomed in beyond 1:10000 and zoomed out beyond 1:6000.

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

Publishing the map service

In order to create the cache, you must first publish your map as a service. You can use either ArcGIS Server Manager or ArcCatalog to do this. These instructions will use ArcCatalog, since you’ll be using ArcCatalog anyway to create the cache. Caching is only available in ArcCatalog.

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

  1. Open ArcCatalog, and create an administrative connection to your GIS server. See Connecting to a GIS server if you need help with this step.
  2. Right-click the connection and click Add New Service.
  3. Enter a Name for the service and click Next.
  4. Fill in the Map Document box by browsing to the map document you created. Your SOC account should have permissions to read this document and any data it references.
  5. Fill in the Server Cache Directory box by using the dropdown to select 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 select the default capabilities for the service.
  7. Now you’re at the panel of the wizard where you can choose the pooling model and number of instances for the service. For cached services, you should always select the default of Pooled. You may, however, want to raise or lower the Maximum number of instances to something 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 of 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.

    Pooling options in the Add GIS Service wizard

    Tip: You may wonder if you need to set the timeout value to something greater than the default, since creating the cache can take a long time. Actually, the caching tools reset the timeout value to be very large before they start creating tiles, so you do not need to change the default timeout 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 panel, choose Yes, start the service right now and click Finish to create the service.
  9. Use the ArcCatalog 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, 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 caching tools. Since the service doesn’t have a cache yet, the only tool available is the cache generation tool, so click the Generate button.
  3. Take a minute to examine some of the parameters for the tool. The first few properties are filled in automatically with values that the tool read directly from the service. Skip down to the Scales dropdown and select CUSTOM.
  4. In the Scales (optional) box, type one of your scales. Then click the Add (+) button. You should see the scale appear in the list below.

    Note: The tool does not accept values that use fractions or colons, so instead of typing the scale you actually need to enter the scale factor. For example, if the scale is 1:80000, enter 80000.

  5. Continue entering scales and clicking the Add (+) button for each one until you have reached the end of your list.

    Cache scales in the GenerateMapServerCache tool
  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.

    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 select PNG8 instead.

  7. Optionally, change the Number of MapServer Instances. This number is a measure of the server computing power you want to dedicate toward creating your cache.

    If you want to dedicate all of your resources to creating the cache, set a high number here. You can only set a number up to the Maximum number of instances property you set on the map service (see above instructions for Publishing the map service).

    If you only have one ArcGIS Server machine that needs to fill other requests while creating the cache, you might want to keep or decrease the default number of instances. This will ensure that the caching job does not consume all of your server resources. Just remember that the fewer the number of instances you dedicate toward cache generation, the longer it will take to create the cache.

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

The cache can take a while to generate, depending on your largest scale, the extent of your data, and other factors. 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. More likely, it will only take a few minutes.

Viewing the progress of the cache

You can use Windows Explorer to get a rough view of the progress of the cache generation.

  1. Open Windows Explorer or My Computer.
  2. Navigate to your server cache directory.
  3. Navigate to <Service name>\<Data frame name>\_alllayers\L00. You’ll see a few folders that represent the rows of the smallest scale in your cache. Expand one of these folders and you can see some of the actual cached images.
  4. Go back up to the _alllayers folder and examine the folders prefixed with L (L00, L01, etc.). These folders represent the different scale levels in your cache. The timestamp on the folder tells you when it was generated. Each successive scale level takes longer to generate because it contains more tiles. In our case, where we doubled the scale, each scale level contains four times as many tiles as the previous level.

    Cache tiles viewed in Windows Explorer

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. In the Home tab of Manager click Create a Web application.
  2. Enter a name for your Web application and, optionally, a description. Then click Next.
  3. In this panel, you’ll indicate that you want your cached map service to appear in the map. If necessary, add your GIS server to the list. Then browse to your cached map service and click Add > to add it to the map. If you need help with this step, see Selecting layers to display.
  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. Expand the Navigation panel. If the Zoom Level slider control appears, the application is successfully using your cache.

    Zoom level control
  6. Pan around the map and zoom to the different levels. When zooming and panning the map, you should see the map tiles appear very quickly.

Troubleshooting

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

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 > 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.

    Media tab in Mozilla Firefox Page Info

Further reading