Fix race condition caused by concurrent access to global cache

parent #437 
You could refactor this in to a `ConcurrencyUtilities.ExecuteFileOperation(string fileName, Action action)` or something like that. The last one is different, but the other 3 cases could be refactored. Also use named params for the first two ints.