Fix caching bugs