From 3c40fa27823e70215261d3845275360f85e59623 Mon Sep 17 00:00:00 2001 From: saturneric Date: Fri, 5 Jan 2024 16:11:24 +0800 Subject: fix: slove some known issues --- src/core/function/CacheManager.cpp | 57 +++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 28 deletions(-) (limited to 'src/core/function/CacheManager.cpp') diff --git a/src/core/function/CacheManager.cpp b/src/core/function/CacheManager.cpp index 80d5aeb4..f9fa41ac 100644 --- a/src/core/function/CacheManager.cpp +++ b/src/core/function/CacheManager.cpp @@ -91,15 +91,13 @@ class ThreadSafeMap { mutable std::shared_mutex mutex_; }; -class CacheManager::Impl : public SingletonFunctionObject { +class CacheManager::Impl : public QObject { + Q_OBJECT public: - Impl(CacheManager* parent, int channel) - : SingletonFunctionObject(channel), - parent_(parent), - m_timer_(new QTimer(parent)) { - connect(m_timer_, &QTimer::timeout, parent_, - [this]() { flush_cache_storage(); }); - m_timer_->start(15000); + Impl() : flush_timer_(new QTimer(this)) { + connect(flush_timer_, &QTimer::timeout, this, + &Impl::slot_flush_cache_storage); + flush_timer_->start(15000); load_all_cache_storage(); } @@ -115,7 +113,7 @@ class CacheManager::Impl : public SingletonFunctionObject { } if (flush) { - flush_cache_storage(); + slot_flush_cache_storage(); } } @@ -153,11 +151,28 @@ class CacheManager::Impl : public SingletonFunctionObject { return cache_storage_.remove(key); } + private slots: + + /** + * @brief + * + */ + void slot_flush_cache_storage() { + for (const auto& cache : cache_storage_.mirror()) { + auto key = get_data_object_key(cache.first); + SPDLOG_TRACE("save cache into filesystem, key {}, value size: {}", key, + cache.second.size()); + GpgFrontend::DataObjectOperator::GetInstance().SaveDataObj(key, + cache.second); + } + GpgFrontend::DataObjectOperator::GetInstance().SaveDataObj(drk_key_, + key_storage_); + } + private: - CacheManager* parent_; ThreadSafeMap cache_storage_; nlohmann::json key_storage_; - QTimer* m_timer_; + QTimer* flush_timer_; const std::string drk_key_ = "__cache_manage_data_register_key_list"; /** @@ -219,22 +234,6 @@ class CacheManager::Impl : public SingletonFunctionObject { key_storage_ = registered_key_list; } - /** - * @brief - * - */ - void flush_cache_storage() { - for (const auto& cache : cache_storage_.mirror()) { - auto key = get_data_object_key(cache.first); - SPDLOG_TRACE("save cache into filesystem, key {}, value size: {}", key, - cache.second.size()); - GpgFrontend::DataObjectOperator::GetInstance().SaveDataObj(key, - cache.second); - } - GpgFrontend::DataObjectOperator::GetInstance().SaveDataObj(drk_key_, - key_storage_); - } - /** * @brief * @@ -245,7 +244,7 @@ class CacheManager::Impl : public SingletonFunctionObject { CacheManager::CacheManager(int channel) : SingletonFunctionObject(channel), - p_(SecureCreateUniqueObject(this, channel)) {} + p_(SecureCreateUniqueObject()) {} CacheManager::~CacheManager() = default; @@ -268,3 +267,5 @@ auto CacheManager::ResetCache(std::string key) -> bool { } } // namespace GpgFrontend + +#include "CacheManager.moc" \ No newline at end of file -- cgit v1.2.3