QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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 #define SIP_NO_FILE
22 
23 #include <QNetworkDiskCache>
24 #include <QMutex>
25 
26 class QNetworkDiskCache;
27 
29 
30 class ExpirableNetworkDiskCache : public QNetworkDiskCache
31 {
32  Q_OBJECT
33 
34  public:
35  explicit ExpirableNetworkDiskCache( QObject *parent = nullptr ) : QNetworkDiskCache( parent ) {}
36  qint64 runExpire() { return QNetworkDiskCache::expire(); }
37 };
38 
40 
48 class QgsNetworkDiskCache : public QNetworkDiskCache
49 {
50  Q_OBJECT
51 
52  public:
53 
55  QString cacheDirectory() const;
56 
58  void setCacheDirectory( const QString &cacheDir );
59 
61  qint64 maximumCacheSize() const;
62 
64  void setMaximumCacheSize( qint64 size );
65 
67  QNetworkCacheMetaData metaData( const QUrl &url ) override;
68 
70  void updateMetaData( const QNetworkCacheMetaData &metaData ) override;
71 
73  QIODevice *data( const QUrl &url ) override;
74 
76  bool remove( const QUrl &url ) override;
77 
79  qint64 cacheSize() const override;
80 
82  QIODevice *prepare( const QNetworkCacheMetaData &metaData ) override;
83 
85  void insert( QIODevice *device ) override;
86 
88  QNetworkCacheMetaData fileMetaData( const QString &fileName ) const;
89 
90  public slots:
92  void clear() override;
93 
94  protected:
96  qint64 expire() override;
97 
98  private:
99  explicit QgsNetworkDiskCache( QObject *parent );
100 
101  static ExpirableNetworkDiskCache sDiskCache;
102  static QMutex sDiskCacheMutex;
103 
105 };
106 
107 #endif // QGSNETWORKDISKCACHE_H
QgsNetworkDiskCache
Definition: qgsnetworkdiskcache.h:48
QgsNetworkDiskCache::cacheDirectory
QString cacheDirectory() const
Definition: qgsnetworkdiskcache.cpp:31
QgsNetworkDiskCache::prepare
QIODevice * prepare(const QNetworkCacheMetaData &metaData) override
Definition: qgsnetworkdiskcache.cpp:85
QgsNetworkDiskCache::metaData
QNetworkCacheMetaData metaData(const QUrl &url) override
Definition: qgsnetworkdiskcache.cpp:61
QgsNetworkDiskCache::setMaximumCacheSize
void setMaximumCacheSize(qint64 size)
Definition: qgsnetworkdiskcache.cpp:49
QgsNetworkDiskCache::setCacheDirectory
void setCacheDirectory(const QString &cacheDir)
Definition: qgsnetworkdiskcache.cpp:37
QgsNetworkDiskCache::fileMetaData
QNetworkCacheMetaData fileMetaData(const QString &fileName) const
Definition: qgsnetworkdiskcache.cpp:97
QgsNetworkDiskCache::updateMetaData
void updateMetaData(const QNetworkCacheMetaData &metaData) override
Definition: qgsnetworkdiskcache.cpp:67
QgsNetworkAccessManager
network access manager for QGIS
Definition: qgsnetworkaccessmanager.h:251
QgsNetworkDiskCache::maximumCacheSize
qint64 maximumCacheSize() const
Definition: qgsnetworkdiskcache.cpp:43
QgsNetworkDiskCache::cacheSize
qint64 cacheSize() const override
Definition: qgsnetworkdiskcache.cpp:55
QgsNetworkDiskCache::data
QIODevice * data(const QUrl &url) override
Definition: qgsnetworkdiskcache.cpp:73
QgsNetworkDiskCache::insert
void insert(QIODevice *device) override
Definition: qgsnetworkdiskcache.cpp:91
QgsNetworkDiskCache::clear
void clear() override
Definition: qgsnetworkdiskcache.cpp:109
QgsNetworkDiskCache::expire
qint64 expire() override
Definition: qgsnetworkdiskcache.cpp:103
QgsNetworkDiskCache::remove
bool remove(const QUrl &url) override
Definition: qgsnetworkdiskcache.cpp:79