I use in_memory workspaces to speed up some Python script tools that get published as Geoprocessing Services significantly.
The tools open MXDs and perform, among other things, an ExportToPDF.
In the MXD there is a layer that references a dataset stored on disk.
At runtime a new dataset gets created with the same schema as that above, so that it can replace it as the data source but, given a choice, I would like that new dataset to ONLY be written to the in_memory workspace.
My testing suggests that using in_memory workspaces like this is not supported by either Layer.replaceDataSource or Layer.findAndReplaceWorkspacePath.
Is there a way to replace the data source of a layer with a feature class stored in the in_memory workspace so that it can be displayed in a map that gets exported to PDF before the in_memory workspace is deleted?
It looks like this would possible using ArcObjects and an InMemoryWorkspaceFactory but here I need an ArcPy solution.
If there is no way to do this using ArcPy at ArcGIS 10.0 (and nothing coming at 10.1) then what I will do is to propose as an ArcGIS Idea that Layer.replaceDataSource be enhanced to support a workspace_type=INMEMORY_WORKSPACE option.
Note: I have also posted this to the ArcGIS Discussion Forums but have had no replies there so far.
An ArcGIS Idea has also been submitted for this to be enhanced.