| 58 | void flush() override {} |
| 59 | |
| 60 | mgb::Maybe<Blob> get(const std::string& category, const Blob& key) override { |
| 61 | MGB_LOCK_GUARD(m_mtx); |
| 62 | auto mem_result = m_local->get(category, key); |
| 63 | if (mem_result.valid()) { |
| 64 | return mem_result; |
| 65 | } |
| 66 | std::string key_str(static_cast<const char*>(key.ptr), key.size); |
| 67 | std::string redis_key_str; |
| 68 | encode(category + '@' + key_str, redis_key_str, 24); |
| 69 | auto result = m_client.get(m_prefix + redis_key_str); |
| 70 | sync(); |
| 71 | auto content = result.get(); |
| 72 | if (content.is_null()) { |
| 73 | return None; |
| 74 | } |
| 75 | std::string decode_content; |
| 76 | mgb_assert(content.is_string()); |
| 77 | decode(content.as_string(), decode_content); |
| 78 | m_local->put(category, key, {decode_content.data(), decode_content.length()}); |
| 79 | return m_local->get(category, key); |
| 80 | } |
| 81 | |
| 82 | void put(const std::string& category, const Blob& key, const Blob& value) override { |
| 83 | MGB_LOCK_GUARD(m_mtx); |
no test coverage detected