QGIS API Documentation 4.1.0-Master (5bf3c20f3c9)
Loading...
Searching...
No Matches
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
22#include "qgis_core.h"
23
24#include <QMutex>
25#include <QNetworkDiskCache>
26
27#define SIP_NO_FILE
28
29class QNetworkDiskCache;
30
32
33class ExpirableNetworkDiskCache : public QNetworkDiskCache
34{
35 Q_OBJECT
36
37 public:
38 explicit ExpirableNetworkDiskCache( QObject *parent = nullptr )
39 : QNetworkDiskCache( parent )
40 {}
41 qint64 runExpire() { return QNetworkDiskCache::expire(); }
42};
43
45
53class CORE_EXPORT QgsNetworkDiskCache : public QNetworkDiskCache
54{
55 Q_OBJECT
56
57 public:
67 void insertPendingRequestHeaders( const QUrl &url, const QVariantMap &headers );
68
79 bool hasPendingRequestForUrl( const QUrl &url ) const;
80
91 void removePendingRequestForUrl( const QUrl &url ) const;
92
106 bool hasInvalidMatchForRequest( const QNetworkRequest &request );
107
109 QString cacheDirectory() const;
110
112 void setCacheDirectory( const QString &cacheDir );
113
115 qint64 maximumCacheSize() const;
116
118 void setMaximumCacheSize( qint64 size );
119
121 QNetworkCacheMetaData metaData( const QUrl &url ) override;
122
124 void updateMetaData( const QNetworkCacheMetaData &metaData ) override;
125
127 QIODevice *data( const QUrl &url ) override;
128
130 bool remove( const QUrl &url ) override;
131
133 qint64 cacheSize() const override;
134
136 QIODevice *prepare( const QNetworkCacheMetaData &metaData ) override;
137
139 void insert( QIODevice *device ) override;
140
142 QNetworkCacheMetaData fileMetaData( const QString &fileName ) const;
143
148 static qint64 smartCacheSize( const QString &path );
149
150 public slots:
152 void clear() override;
153
154 protected:
156 qint64 expire() override;
157
158 private:
159 explicit QgsNetworkDiskCache( QObject *parent );
160
161 static ExpirableNetworkDiskCache sDiskCache;
162 static QMutex sDiskCacheMutex;
163
164 static QHash<QUrl, QVariantMap> sPendingRequestHeaders;
165
167};
168
169#endif // QGSNETWORKDISKCACHE_H
void setCacheDirectory(const QString &cacheDir)
void removePendingRequestForUrl(const QUrl &url) const
Removes a pending (ongoing) request in place for the specified url.
QIODevice * data(const QUrl &url) override
void updateMetaData(const QNetworkCacheMetaData &metaData) override
QNetworkCacheMetaData metaData(const QUrl &url) override
bool hasInvalidMatchForRequest(const QNetworkRequest &request)
Returns true if the cache has a matching but invalid entry for a request.
QNetworkCacheMetaData fileMetaData(const QString &fileName) const
bool hasPendingRequestForUrl(const QUrl &url) const
Returns true if there is a pending (ongoing) request in place for the specified url.
friend class QgsNetworkAccessManager
void insertPendingRequestHeaders(const QUrl &url, const QVariantMap &headers)
Registers the original request headers for a pending request to the specified url.
void insert(QIODevice *device) override
QIODevice * prepare(const QNetworkCacheMetaData &metaData) override
bool remove(const QUrl &url) override
void setMaximumCacheSize(qint64 size)
qint64 cacheSize() const override
static qint64 smartCacheSize(const QString &path)
Returns a smart cache size, in bytes, based on available free space.