#pragma once #include #include #include #include #include #include #include "util.hpp" // todo throttle requests and keep track of active requests to stop redundant requests class Cache { public: Cache(); ~Cache(); using callback_type = std::function; void GetFileFromURL(std::string url, callback_type cb); std::string GetPathIfCached(std::string url); private: std::string GetCachedName(std::string str); void CleanupFutures(); void RespondFromPath(std::filesystem::path path, callback_type cb); void OnResponse(const cpr::Response &r); std::unique_ptr m_semaphore; std::unordered_map> m_callbacks; std::vector> m_futures; std::filesystem::path m_tmp_path; bool m_canceled = false; };