QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
qgsnetworkdiskcache.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsnetworkdiskcache.h - Thread-safe interface for QNetworkDiskCache
3  -------------------
4  begin : 2016-03-05
5  copyright : (C) 2016 by Juergen E. Fischer
6  email : jef at norbit dot de
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #ifndef QGSNETWORKDISKCACHE_H
19 #define QGSNETWORKDISKCACHE_H
20 
21 #include <QNetworkDiskCache>
22 #include <QMutex>
23 
24 class QNetworkDiskCache;
25 
33 {
34  Q_OBJECT
35 
36  public:
38 
40  QString cacheDirectory() const;
41 
43  void setCacheDirectory( const QString &cacheDir );
44 
46  qint64 maximumCacheSize() const;
47 
49  void setMaximumCacheSize( qint64 size );
50 
52  QNetworkCacheMetaData metaData( const QUrl &url ) override;
53 
55  void updateMetaData( const QNetworkCacheMetaData &metaData ) override;
56 
58  QIODevice *data( const QUrl &url ) override;
59 
61  bool remove( const QUrl &url ) override;
62 
64  qint64 cacheSize() const override;
65 
67  QIODevice *prepare( const QNetworkCacheMetaData &metaData ) override;
68 
70  void insert( QIODevice *device ) override;
71 
73  QNetworkCacheMetaData fileMetaData( const QString &fileName ) const;
74 
75  public slots:
77  void clear() override;
78 
79  protected:
81  virtual qint64 expire() override;
82 
83  private:
84  explicit QgsNetworkDiskCache( QObject *parent );
85  Q_DISABLE_COPY( QgsNetworkDiskCache )
86 
87  class ExpirableNetworkDiskCache : public QNetworkDiskCache
88  {
89  public:
90  explicit ExpirableNetworkDiskCache( QObject *parent = 0 ) : QNetworkDiskCache( parent ) {}
91  qint64 runExpire() { return QNetworkDiskCache::expire(); }
92  };
93 
94  static ExpirableNetworkDiskCache smDiskCache;
95  static QMutex smDiskCacheMutex;
96 
98 };
99 
100 #endif // QGSNETWORKDISKCACHE_H
qint64 cacheSize() const override
void setCacheDirectory(const QString &cacheDir)
void updateMetaData(const QNetworkCacheMetaData &metaData) override
QNetworkDiskCache(QObject *parent)
void insert(QIODevice *device) override
QString cacheDirectory() const
QNetworkCacheMetaData fileMetaData(const QString &fileName) const
virtual qint64 expire() override
virtual qint64 expire()
QNetworkCacheMetaData metaData(const QUrl &url) override
qint64 maximumCacheSize() const
QIODevice * data(const QUrl &url) override
QIODevice * prepare(const QNetworkCacheMetaData &metaData) override
QObject * parent() const
network access manager for QGIS
void setMaximumCacheSize(qint64 size)
Wrapper implementation of QNetworkDiskCache with all methods guarded by a mutex soly for internal use...