File indexing completed on 2025-01-05 04:47:02
0001 /* 0002 SPDX-FileCopyrightText: 2007 Volker Krause <vkrause@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include "collectionscheduler.h" 0010 0011 #include <QMutex> 0012 0013 namespace Akonadi 0014 { 0015 namespace Server 0016 { 0017 class Collection; 0018 class CacheCleaner; 0019 class AkonadiServer; 0020 0021 /** 0022 * A RAII helper class to temporarily stop the CacheCleaner. This allows long-lasting 0023 * operations to safely retrieve all data from resource and perform an operation on them 0024 * (like move or copy) without risking that the cache will be cleaned in the meanwhile 0025 * 0026 * The inhibitor is recursive, so it's possible to create multiple instances of the 0027 * CacheCleanerInhibitor and the CacheCleaner will be inhibited until all instances 0028 * are destroyed again. However it's not possible to inhibit a single inhibitor 0029 * multiple times. 0030 */ 0031 class CacheCleanerInhibitor 0032 { 0033 public: 0034 explicit CacheCleanerInhibitor(AkonadiServer &akonadi, bool inhibit = true); 0035 ~CacheCleanerInhibitor(); 0036 0037 void inhibit(); 0038 void uninhibit(); 0039 0040 private: 0041 Q_DISABLE_COPY(CacheCleanerInhibitor) 0042 static QMutex sLock; 0043 static int sInhibitCount; 0044 0045 CacheCleaner *mCleaner = nullptr; 0046 bool mInhibited = false; 0047 }; 0048 0049 /** 0050 Cache cleaner. 0051 */ 0052 class CacheCleaner : public CollectionScheduler 0053 { 0054 Q_OBJECT 0055 0056 protected: 0057 /** 0058 Creates a new cache cleaner thread. Use AkThread::create() to create a new instance of CacheCleaner. 0059 @param parent The parent object. 0060 */ 0061 explicit CacheCleaner(QObject *parent = nullptr); 0062 0063 public: 0064 ~CacheCleaner() override; 0065 0066 protected: 0067 void collectionExpired(const Collection &collection) override; 0068 int collectionScheduleInterval(const Collection &collection) override; 0069 bool hasChanged(const Collection &collection, const Collection &changed) override; 0070 bool shouldScheduleCollection(const Collection &collection) override; 0071 0072 private: 0073 friend class CacheCleanerInhibitor; 0074 }; 0075 0076 } // namespace Server 0077 } // namespace Akonadi