Clear Workspace Cache in Python

5807
2
Jump to solution
11-15-2012 10:23 AM
ChanningDale
New Contributor III
I want to use the Clear Workspace Cache tool in a geoprocessing service published from a Python toolbox in ArcGIS 10.1, because I need a way to clear/refresh SDE database connections for the service to run properly.  When I use this tool in my script, it does not have any affect on the established connections made by the service.  To test to see if the tool actually worked, I created a simple model in Model Builder using the Make Feature Layer tool and Feature Class to Feature Class tool, and setting Clear Workspace Cache as a precondition before running the previous two tools.

The reason why I used these tools in my example is that, I came across an issue with adding new features to a feature service and running Make Feature Layer to create a layer from those newly added features.  When you have a fresh geoprocessing service, and you pass a query into the Make Feature Layer tool to make the layer from the newly added features, the layer gets successfully created with those features.  Say you have the feature service in a Flex viewer, and you end your session, come back to it, add new features, and run the geoprocessing service, the feature layer will NOT get created because the previous connections made by the geoprocessing service from the original session have (assumingly) not been refreshed or reconnected to see the newly added features.  The same "blind" behavior occurs in ArcMap.

Now, Clear Workspace Cache seems to get rid of this problem IF I use it in Model Builder as a precondition and publish the whole model as a geoprocessing service.  When I add the tool to my Python script, that precondition logic is lost and I'm stuck with not getting the new features that I need after editing to make my feature layer.

Hopefully this makes some sense.  It's caused quite the headache.  Thoughts?  Is there any way to simulate the Model Builder preconition in my script besides placing the tool call at the top of the script before everything else runs?
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
ChanningDale
New Contributor III
I ended up not using the Clear Workspace Cache tool and couldn't figure out a solution with it.  So, we ended up moving the main body of code to a standalone Python script that is called from the Python toolbox using subprocess.  Connections aren't getting refreshed in ArcGIS Server, so we had to move the script to its own process that gets called every time.  Adds an extra file to run, but it works.

View solution in original post

0 Kudos
2 Replies
DanielAbera
New Contributor III
What if you use the del function. For Instance if you connection is like this

SDEConn = arcpy.CreateArcSDEConnectionFile_management (folderName, fileName, serverName, serviceName, databaseName, authType, username, password, saveUserInfo, versionName, saveVersionInfo)

del SDEConn



I didn't test it, just curious .

Daniel A.
0 Kudos
ChanningDale
New Contributor III
I ended up not using the Clear Workspace Cache tool and couldn't figure out a solution with it.  So, we ended up moving the main body of code to a standalone Python script that is called from the Python toolbox using subprocess.  Connections aren't getting refreshed in ArcGIS Server, so we had to move the script to its own process that gets called every time.  Adds an extra file to run, but it works.
0 Kudos