Utility function for caching API calls