Fix a few bugs around caching