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?