Limit the amount of transformations inside the cache storage

This commit is contained in:
Felipe Zimmerle 2015-11-04 16:20:31 -03:00
parent 5bef19aa4d
commit 45638ccc91
6 changed files with 21 additions and 3 deletions

View File

@ -47,7 +47,7 @@ std::string HtmlEntityDecode::evaluate(std::string value,
ret.assign(tmp);
free(tmp);
HtmlEntityDecodeInstantCache::getInstance().emplace(value, ret);
HtmlEntityDecodeInstantCache::getInstance().cache(value, ret);
return ret;
}

View File

@ -37,6 +37,12 @@ class HtmlEntityDecodeInstantCache : public std::unordered_map<std::string, std:
return instance;
}
void cache(const std::string& value, const std::string& out) {
emplace(value, out);
if (size() > 100) {
erase(begin());
}
}
private:
HtmlEntityDecodeInstantCache() {};
};

View File

@ -45,7 +45,7 @@ std::string LowerCase::evaluate(std::string value,
value[i] = std::tolower(value[i], loc);
}
LowerCaseInstantCache::getInstance().emplace(orig_value, value);
LowerCaseInstantCache::getInstance().cache(orig_value, value);
return value;
}

View File

@ -36,6 +36,12 @@ class LowerCaseInstantCache : public std::unordered_map<std::string, std::string
return instance;
}
void cache(const std::string& value, const std::string& out) {
emplace(value, out);
if (size() > 100) {
erase(begin());
}
}
private:
LowerCaseInstantCache() {};
};

View File

@ -116,7 +116,7 @@ std::string UrlDecode::evaluate(std::string value,
free(val);
UrlDecodeInstantCache::getInstance().emplace(value, out);
UrlDecodeInstantCache::getInstance().cache(value, out);
return out;
}

View File

@ -36,6 +36,12 @@ class UrlDecodeInstantCache : public std::unordered_map<std::string, std::string
return instance;
}
void cache(const std::string& value, const std::string& out) {
emplace(value, out);
if (size() > 100) {
erase(begin());
}
}
private:
UrlDecodeInstantCache() {};
};