Tutorial: Creating a cached map service

Release 9.3 E-mail This Topic Printable Version Give Us Feedback

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 dropdown list in ArcMap:

  1. Click the dropdown list of scales in ArcMap.
  2. Click <Customize this 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.

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

  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:

    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 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 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. Start 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. 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. You can, however, 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.

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

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

  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.

    If you want to dedicate all 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 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.

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

The cache can take awhile 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.

On Linux/Solaris, you can create/update cache from command line.

Viewing the progress of the cache

You can use Windows Explorer on Windows or navigate to the cache location on Linux/Solaris to get a rough view of the progress of the cache generation.

  1. On Windows, open Windows Explorer or My Computer. On Linux/Solaris, just switch to your cache directory.
  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, and so on). These folders represent the different scale levels in your cache. The time stamp on the folder tells you when it was generated. Each successive scale level takes longer to generate because it contains more tiles. In this case, where you doubled the scale, each scale level contains four times as many tiles as the previous level.

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, 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 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. The levels in the zoom-level slider correspond to the scales in your cache.

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

Further reading