QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
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
network access manager for QGISThis class implements the QGIS network access manager.
Wrapper implementation of QNetworkDiskCache with all methods guarded by a mutex soly for internal use...