Fix race condition caused by concurrent access to global cache

parent #437