Delete Map Server Cache (Server)

Summary

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

Usage

Syntax

DeleteMapServerCache_Server (server_name, object_name, data_frame, Layer)
ParameterExplanationData Type
server_name

The ArcGIS Server machine hosting the service whose cache will be deleted.

String
object_name

The map service whose cache will be deleted.

String
data_frame

The source data frame of the cache to be deleted. This appears in the user interface for informational purposes only and cannot be changed.

String
Layer
[Layer,...]

The layers to delete from the cache (only applies to multilayer caches). Layers that are included will be removed from the cache. Excluded layers will remain.

String

Code Sample

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

# DeleteMapServerCache example (stand-alone script)

# Name: DeleteMapServerCache.py
# 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
# Author: ESRI

# 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
server = "MyServer"
service = "Rainfall"
dataFrame = "" 
layer = ""

currentTime = datetime.datetime.now()
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
try:
    starttime = time.clock()
    result = arcpy.DeleteMapServerCache_server(server, service, dataFrame, layer)
    finishtime = time.clock()
    elapsedtime = finishtime - starttime

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

    print "Deleted cache tiles & schema for mapservice " + service + "\n   at "
    + cacheDir + service + " in " + str(elapsedtime) + " sec \n on " + arg2
    
except Exception, e:
    # If an error occurred, print line number and error message
    tb = sys.exc_info()[2]
    report.write("Failed at step 1 \n" "Line %i" % tb.tb_lineno)
    report.write(e.message)


print "Deleted Map server Cache Tiles "

report.close()

Environments

This tool does not use any geoprocessing environments

Related Topics

Licensing Information

ArcView: Yes
ArcEditor: Yes
ArcInfo: Yes

5/9/2011