| 93 | } |
| 94 | |
| 95 | std::optional<size_t> clear() override { |
| 96 | long long cursor = 0; |
| 97 | size_t nr_deleted = 0; |
| 98 | std::string pattern = m_prefix + "*"; |
| 99 | do { |
| 100 | auto reply = m_client.scan(cursor, pattern).share(); |
| 101 | sync(); |
| 102 | auto keys = reply.get().as_array(); |
| 103 | std::vector<std::string> string_keys; |
| 104 | for (auto&& key : keys[1].as_array()) { |
| 105 | string_keys.push_back(key.as_string()); |
| 106 | } |
| 107 | m_client.del(string_keys); |
| 108 | nr_deleted += string_keys.size(); |
| 109 | cursor = std::stoll(keys[0].as_string()); |
| 110 | } while (cursor != 0); |
| 111 | return nr_deleted; |
| 112 | } |
| 113 | |
| 114 | private: |
| 115 | std::shared_ptr<mgb::PersistentCache> m_local; |