Fix race condition caused by concurrent access to global cache

parent #437 
Ah, good point!