Move API and caching logic into a separate class