Improve error handling for cacheData