Fix race condition caused by concurrent access to global cache

parent #437 
Would this be an else condition to the previous `if`?