Automating cache creation and updates with geoprocessing
In this topic
If you're working with a basemap that is unlikely to change, chances are you'll create its cache only once. You can launch ArcGIS geoprocessing tools to create the cache and add tiles to it. This is also an appropriate way to update the cache if your data does not change very often.
If your data changes often, you still might be able to use caching. The caching tools have been designed to allow you to script cache updates and target specific parts of the cache for updates. For example, you can do the following:
- Update the cache only for scale levels that have changed.
- Update only areas of the cache that fall within the boundaries of a feature class.
- Automate cache maintenance.
The way to automate the caching process is to write scripts that use tools from the Caching toolset in the Server Tools toolbox. This toolset contains tools for both map caching and globe caching.
To create a new map or image service cache, you will typically start with Create Map Server Cache tool, which initializes the cache. Then you run Manage Map Server Cache Tiles to add tiles to the cache.
To build a globe service cache, you just need to run the Manage Globe Server Cache Tiles tool. By nature, all globe services have a cache that is automatically created when you start the service. This cache uses a built-in tiling scheme that is the same for all globe services. Therefore, there are no tools for creating a new globe cache or tiling scheme.
There are many tools that work with exporting, importing, and deleting caches. For a summary of all available tools, see An overview of the Caching toolset.
Using the tools in scripts
Although you can manually open the caching tools from the Catalog or Search window, it's more efficient to create a model in ModelBuilder or write a geoprocessing script that contains one or more tools that you want to run. You can then schedule scripts to run automatically.
The geoprocessing tool reference topic contains a full Python code sample showing how to use the tool in a script. For example, see the help for Manage Map Server Cache Tiles.
If you're new to Python, these resources can help you learn more:
- What is Python?—The ArcGIS Help contains an introduction to Python scripting, starting with this topic.
- Exporting a model—If you've created models in ModelBuilder, you can export them to Python to see what the corresponding script looks like.
Running scripts on Linux
When running Python scripts that use the ArcGIS module arcpy, follow the steps in Deploying custom python packages.
Scheduling your script to run on a regular basis
You can save your script as a Python script file (.py). Double-clicking the script will cause the script to run. This is useful for testing, but in most cases, you'll want to schedule the script to run automatically on a regular basis.
Your operating system contains utilities that help you schedule tasks such as running a script. You'll need to provide the location of the script file, how often you want it to run, and the name and password that the task will run as. For further reading, see Scheduling a Python script to run at prescribed times.