Rework the caching in an attempt to fix locking behaviour