提交 53d48ca3 编写于 作者: M Megvii Engine Team

fix(fastrun): persistent cache add prefix

(cherry picked from commit bdd82c1976a79a267f73d637867e8c6bebf49984)

GitOrigin-RevId: 0b13d3217516bc92f7278d335a4a81c57995f269
上级 7005b7d6
...@@ -84,7 +84,7 @@ class PersistentCacheOnServer(_PersistentCache): ...@@ -84,7 +84,7 @@ class PersistentCacheOnServer(_PersistentCache):
if url is None: if url is None:
return None return None
assert sys.platform != "win32", "redis cache on windows not tested" assert sys.platform != "win32", "redis cache on windows not tested"
prefix = "mgbcache:{}:MGB{}:GIT:{}".format( prefix = "mgbcache:{}:MGB{}:GIT:{}::".format(
getpass.getuser(), __version__, git_version getpass.getuser(), __version__, git_version
) )
parse_result = urllib.parse.urlparse(url) parse_result = urllib.parse.urlparse(url)
......
...@@ -71,21 +71,21 @@ public: ...@@ -71,21 +71,21 @@ public:
mgb::Maybe<Blob> get(const std::string& category, const Blob& key) override { mgb::Maybe<Blob> get(const std::string& category, const Blob& key) override {
MGB_LOCK_GUARD(m_mtx); MGB_LOCK_GUARD(m_mtx);
auto mem_result = m_local->get(category, key); auto mem_result = m_local->get(category, key);
if (mem_result.valid()) if (mem_result.valid()) {
return mem_result; return mem_result;
}
std::string key_str(static_cast<const char*>(key.ptr), key.size); std::string key_str(static_cast<const char*>(key.ptr), key.size);
std::string redis_key_str; std::string redis_key_str;
encode(category + '@' + key_str, redis_key_str, 24); encode(category + '@' + key_str, redis_key_str, 24);
auto result = m_client.get(redis_key_str); auto result = m_client.get(m_prefix + redis_key_str);
sync(); sync();
auto content = result.get(); auto content = result.get();
if (content.is_null()) if (content.is_null()) {
return mgb::None; return None;
}
std::string decode_content; std::string decode_content;
decode(content.as_string(), decode_content); decode(content.as_string(), decode_content);
m_local->put(category, key, {decode_content.data(), decode_content.length()}); m_local->put(category, key, {decode_content.data(), decode_content.length()});
return m_local->get(category, key); return m_local->get(category, key);
} }
...@@ -97,8 +97,7 @@ public: ...@@ -97,8 +97,7 @@ public:
std::string value_str(static_cast<const char*>(value.ptr), value.size); std::string value_str(static_cast<const char*>(value.ptr), value.size);
std::string redis_value_str; std::string redis_value_str;
encode(value_str, redis_value_str); encode(value_str, redis_value_str);
auto result = m_client.set(m_prefix + redis_key_str, redis_value_str);
auto result = m_client.set(redis_key_str, redis_value_str);
m_local->put(category, key, value); m_local->put(category, key, value);
sync(); sync();
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册