Fix race condition between accessing database and database cache

for some reason, this race triggered more frequently on MacOS than on Linux.  Or
more frequently for Italians than for Germans.  Or whatever.

In general, we need to get away from keeping state in too many places, and
having too many access parts to those state information!