From 53d48ca399dca35333002a9d9a6c23dca71cb305 Mon Sep 17 00:00:00 2001 From: Megvii Engine Team Date: Tue, 12 Apr 2022 19:30:28 +0800 Subject: [PATCH] fix(fastrun): persistent cache add prefix (cherry picked from commit bdd82c1976a79a267f73d637867e8c6bebf49984) GitOrigin-RevId: 0b13d3217516bc92f7278d335a4a81c57995f269 --- .../python/megengine/utils/persistent_cache.py | 2 +- imperative/src/impl/persistent_cache.cpp | 15 +++++++-------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/imperative/python/megengine/utils/persistent_cache.py b/imperative/python/megengine/utils/persistent_cache.py index b6aadf8ad..ca6965cfb 100644 --- a/imperative/python/megengine/utils/persistent_cache.py +++ b/imperative/python/megengine/utils/persistent_cache.py @@ -84,7 +84,7 @@ class PersistentCacheOnServer(_PersistentCache): if url is None: return None 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 ) parse_result = urllib.parse.urlparse(url) diff --git a/imperative/src/impl/persistent_cache.cpp b/imperative/src/impl/persistent_cache.cpp index 5fc291c8a..757ba04c6 100644 --- a/imperative/src/impl/persistent_cache.cpp +++ b/imperative/src/impl/persistent_cache.cpp @@ -71,21 +71,21 @@ public: mgb::Maybe get(const std::string& category, const Blob& key) override { MGB_LOCK_GUARD(m_mtx); auto mem_result = m_local->get(category, key); - if (mem_result.valid()) + if (mem_result.valid()) { return mem_result; - + } std::string key_str(static_cast(key.ptr), key.size); std::string redis_key_str; 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(); auto content = result.get(); - if (content.is_null()) - return mgb::None; + if (content.is_null()) { + return None; + } std::string decode_content; decode(content.as_string(), decode_content); m_local->put(category, key, {decode_content.data(), decode_content.length()}); - return m_local->get(category, key); } @@ -97,8 +97,7 @@ public: std::string value_str(static_cast(value.ptr), value.size); std::string redis_value_str; encode(value_str, redis_value_str); - - auto result = m_client.set(redis_key_str, redis_value_str); + auto result = m_client.set(m_prefix + redis_key_str, redis_value_str); m_local->put(category, key, value); sync(); } -- GitLab