Fix bugs in the new cache system