[Cache] Added mutex
[ci skip]
This commit is contained in:
parent
c969f5054d
commit
98d9ad402f
@ -10,6 +10,7 @@ namespace Utils
|
||||
*/
|
||||
};
|
||||
std::string Cache::validUrl;
|
||||
std::mutex Cache::CacheMutex;
|
||||
|
||||
Cache::Cache(std::string path)
|
||||
{
|
||||
@ -31,15 +32,22 @@ namespace Utils
|
||||
|
||||
std::string Cache::GetFile(int timeout, std::string useragent)
|
||||
{
|
||||
for (int i = 0; i < ARRAY_SIZE(Cache::urls); i++)
|
||||
if (Cache::validUrl.empty())
|
||||
{
|
||||
std::string result = Utils::WebIO(useragent, this->GetUrl(Cache::urls[i], this->Path)).setTimeout(timeout)->get();
|
||||
if (!result.empty())
|
||||
std::lock_guard<std::mutex> _(Cache::CacheMutex);
|
||||
for (int i = 0; i < ARRAY_SIZE(Cache::urls); i++)
|
||||
{
|
||||
Cache::validUrl = Cache::urls[i];
|
||||
return result;
|
||||
std::string result = Utils::WebIO(useragent, this->GetUrl(Cache::urls[i], this->Path)).setTimeout(timeout)->get();
|
||||
if (!result.empty())
|
||||
{
|
||||
Cache::validUrl = Cache::urls[i];
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
return "";
|
||||
else
|
||||
{
|
||||
return Utils::WebIO(useragent, this->GetUrl(Cache::validUrl, this->Path)).setTimeout(timeout)->get();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,8 @@ namespace Utils
|
||||
std::string GetUrl();
|
||||
std::string GetFile(int timeout = 5000, std::string useragent = "IW4x");
|
||||
|
||||
//private:
|
||||
private:
|
||||
static std::mutex CacheMutex;
|
||||
static const char* urls[];
|
||||
static std::string validUrl;
|
||||
std::string Path;
|
||||
|
Loading…
x
Reference in New Issue
Block a user