Database: Another caching bug

Not ready to merge. The bug is not yet fixed.