Clear Workspace Cache (Data Management)

License Level:BasicStandardAdvanced

Summary

Clears any ArcSDE workspaces from the ArcSDE workspace cache.

Usage

Syntax

ClearWorkspaceCache_management ({in_data})
ParameterExplanationData Type
in_data
(Optional)

The ArcSDE database connection file representing the ArcSDE workspace to be removed from the cache. Specify the path to the ArcSDE connection file that was used in running your geoprocessing tools in order to remove the specific ArcSDE workspace from the cache. Passing no input parameter will clear all ArcSDE workspaces from the cache.

Data Element; Layer

Code Sample

ClearWorkspaceCache Example (Python Window)

The following Python window script demonstrates how to use the ClearWorkspaceCache function in immediate mode.

import arcpy
from arcpy import env
env.workspace = "c:/connectionFiles/Connection to gpserver.sde"
arcpy.ClearWorkspaceCache_management()
Clear Workspace Cache Sample

Sample showing how to disconnect from ArcSDE by clearing the ArcSDE workspace cache. Two methods are shown. 1. Disconnect from a specific connection by specifying the connection file name. 2. Disconnect from all connections by leaving the ArcSDE connection file parameter blank.

# Name: ClearWorkspaceCache_Example.py
# Description: Two examples: 1. Remove the specified ArcSDE workspace from the workspace cache, 
#                               terminating the connection to ArcSDE from this client
#                            2. Remove many ArcSDE workspaces from the workspace cache, 
#                               terminating the connection to ArcSDE from this client for each workspace.

# Import system modules
import arcpy
from arcpy import env

# Set environment settings
env.workspace = "Database Connections\Connection to gpserver.sde" # Creates a connection to ArcSDE
fcList = arcpy.ListFeatureClasses() # Show that we are connected
print str(fcList) + "\n"
env.workspace = "" # Release hold on ArcSDE workspace created in previous step.

# Execute the Clear Workspace Cache tool
arcpy.ClearWorkspaceCache_management("Database Connections\Connection to gpserver.sde")
print arcpy.GetMessages() + "\n"

# Clear the Workspace Cache of multiple connections
# Set environment settings
# Connection 1
env.workspace = "Database Connections\Connection to gpServer.sde" # Creates a connection to ArcSDE
fcList = arcpy.ListFeatureClasses() # Show that we are connected
print str(fcList) + "\n"

# Connection 2
env.workspace = "Database Connections\Connection to ProductionServer.sde" # Creates a connection to ArcSDE
fcList = arcpy.ListFeatureClasses() # Show that we are connected
print str(fcList) + "\n"

# Connection 3
env.workspace = "Database Connections\Connection to TestServer.sde" # Creates a connection to ArcSDE
fcList = arcpy.ListFeatureClasses() # Show that we are connected
print str(fcList) + "\n"
env.workspace = "" # Release hold on ArcSDE workspace created in previous steps.

# Execute the Clear Workspace Cache tool
arcpy.ClearWorkspaceCache_management() # If you do not specify a connection, all ArcSDE workspaces will be removed from the Cache
print arcpy.GetMessages()

Environments

Related Topics

Licensing Information

ArcGIS for Desktop Basic: Yes
ArcGIS for Desktop Standard: Yes
ArcGIS for Desktop Advanced: Yes
5/7/2015