Delete Map Server Cache (Server)


Deletes an existing map image layer cache, including all associated files on disk.


  • This is an unrecoverable operation so only use if you are sure you no longer need the cache. If you want to delete tiles but leave the cache folder structure and tiling scheme, use the Manage Map Server Cache Tiles tool with Update Mode set to DELETE_TILES.

  • After this tool runs, the service will be restarted.


arcpy.server.DeleteMapServerCache(input_service, {num_of_caching_service_instances})
ParameterExplanationData Type

The map image layer whose cache tiles you want to delete.

Image Service; MapServer

Defines the number of instances that will be used to update/generate the tiles. The value for this parameter is set to unlimited (-1) and cannot be modified.


Derived Output

NameExplanationData Type

The output URL.


Code sample

DeleteMapServerCache example (stand-alone script)

This example uses DeleteMapServerCache to delete a cache for a map service named Rainfall.

# Name:
# Description: The following stand-alone script demonstrates how to delete map server cache
#              tiles if the corresponding cache schema or tiles has been created
# Requirements: os, sys, time & traceback modules

# Any line that begins with a pound sign is a comment and will not be executed
# Empty quotes take the default value.
# To accept arguments from the command line replace values of variables to
#                                                           "sys.argv[]"

# Import system modules
import arcpy
from arcpy import env
import os, sys, time, datetime, traceback, string

# Set environment settings
env.workspace = "C:/data"

# List of variables for mapservice properties
connectionFile = r"C:\Users\<username>\AppData\Roaming\ESRI\Desktop10.1\ArcCatalog"
server = "arcgis on MyServer_6080 (publisher)"
serviceName = "Rainfall.MapServer"
inputService = connectionFile + "\\" + server + "\\" + serviceName
numOfCachingServiceInstances = 2

currentTime =
arg1 = currentTime.strftime("%H-%M")
arg2 = currentTime.strftime("%Y-%m-%d %H:%M")
file = 'C:/data/report_%s.txt' % arg1

# print results of the script to a report
report = open (file,'w')

# To Recreate all the tiles for the default number of scales generated
    starttime = time.clock()
    result = arcpy.DeleteMapServerCache_server(inputService,
    finishtime = time.clock()
    elapsedtime = finishtime - starttime

    #print messages to a file
    while result.status < 4:
    resultValue = result.getMessages()
    report.write ("completed " + str(resultValue))

    print("Deleted cache tiles & schema for mapservice " + serviceName + \
        "\n  in " + str(elapsedtime) + " sec \n on " + arg2)

except Exception as e:
    # If an error occurred, print line number and error message
    tb = sys.exc_info()[2]
    report.write("Failed at \n" "Line %i" % tb.tb_lineno)

print("Deleted Map server Cache Tiles ")



This tool does not use any geoprocessing environments.

Licensing information

  • Basic: Yes
  • Standard: Yes
  • Advanced: Yes

Related topics