LeechCraft  0.6.70-16373-g319c272718
Modular cross-platform feature rich live environment.
networkdiskcachegc.h
Go to the documentation of this file.
1 /**********************************************************************
2  * LeechCraft - modular cross-platform feature rich internet client.
3  * Copyright (C) 2006-2014 Georg Rudoy
4  *
5  * Distributed under the Boost Software License, Version 1.0.
6  * (See accompanying file LICENSE or copy at https://www.boost.org/LICENSE_1_0.txt)
7  **********************************************************************/
8 
9 #pragma once
10 
11 #include <functional>
12 #include <list>
13 #include <QObject>
14 #include <QMap>
15 #include <util/sll/util.h>
16 
17 template<typename T>
18 class QFuture;
19 
20 namespace LC::Util
21 {
30  class NetworkDiskCacheGC : public QObject
31  {
32  using CacheSizeGetters_t = std::list<std::function<int ()>>;
34 
35  QMap<QString, qint64> LastSizes_;
36 
37  bool IsCollecting_ = false;
38 
40  public:
41  NetworkDiskCacheGC (const NetworkDiskCacheGC&) = delete;
43 
48  static NetworkDiskCacheGC& Instance ();
49 
60  QFuture<qint64> GetCurrentSize (const QString& path) const;
61 
82  Util::DefaultScopeGuard RegisterDirectory (const QString& path,
83  const std::function<int ()>& sizeGetter);
84  private:
85  void UnregisterDirectory (const QString&, CacheSizeGetters_t::iterator);
86  void HandleCollect ();
87  };
88 }
NetworkDiskCacheGC & operator=(const NetworkDiskCacheGC &)=delete
static NetworkDiskCacheGC & Instance()
Returns a single global instance of the GC manager.
Garbage collection for a set of network disk caches.
QFuture< qint64 > GetCurrentSize(const QString &path) const
Schedules calculation of the path total size.
Util::DefaultScopeGuard RegisterDirectory(const QString &path, const std::function< int()> &sizeGetter)
Registers the given cache path.