Skip To Content

Clear Workspace Cache

Summary

Clears any enterprise geodatabase workspaces from the enterprise geodatabase workspace cache.

Usage

  • This tool only works with enterprise geodatabase workspaces.

  • This tool can be used to help disconnect idle enterprise geodatabase connections in a long-running application.

  • If you run the tool without specifying an Input data element, all enterprise geodatabase workspaces in the enterprise geodatabase workspace cache will be cleared. Specify the specific .sde file associated with the workspace you want to clear in order to clear a specific enterprise geodatabase workspace.

  • Note:
    Clearing an enterprise geodatabase workspace from the enterprise geodatabase workspace cache does not guarantee the connection to the enterprise geodatabase server will be disconnected. It will only ensure the geoprocessor object no longer has any hold on the enterprise geodatabase workspace that has been cleared. If any other process has references to this enterprise geodatabase workspace the connection will be maintained.
    • To clear the workspace cache correctly in a script: The call to ClearWorkspaceCache() should be the last call in your script making sure to remove all references to any objects that may be pointing to the enterprise geodatabase workspace before making the call to ClearWorkspaceCache().

Syntax

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

The enterprise geodatabase database connection file representing the enterprise geodatabase workspace to be removed from the cache. Specify the path to the enterprise geodatabase connection file that was used in running your geoprocessing tools in order to remove the specific enterprise geodatabase workspace from the cache. Passing no input parameter will clear all enterprise geodatabase 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
arcpy.env.workspace = "c:/connectionFiles/Connection to gpserver.sde"
arcpy.ClearWorkspaceCache_management()
Clear Workspace Cache Sample

Sample showing how to disconnect from enterprise geodatabase by clearing the enterprise geodatabase 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 enterprise geodatabase connection file parameter blank.

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

# Import system modules
import arcpy

# Set environment settings
arcpy.env.workspace = "Database Connections\Connection to gpserver.sde" # Creates a connection to enterprise geodatabase
fcList = arcpy.ListFeatureClasses() # Show that we are connected
print(str(fcList) + "\n")
arcpy.env.workspace = "" # Release hold on enterprise geodatabase 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
arcpy.env.workspace = "Database Connections\Connection to gpServer.sde" # Creates a connection to enterprise geodatabase
fcList = arcpy.ListFeatureClasses() # Show that we are connected
print(str(fcList) + "\n")

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

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

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

Environments

Licensing information

  • ArcGIS Desktop Basic: Yes
  • ArcGIS Desktop Standard: Yes
  • ArcGIS Desktop Advanced: Yes

Related topics