Properly synchronize access to instances map when clearing caches