diff options
author | Peter Hartmann <peter.hartmann@trolltech.com> | 2009-06-18 15:50:32 (GMT) |
---|---|---|
committer | Peter Hartmann <peter.hartmann@trolltech.com> | 2009-06-22 13:12:28 (GMT) |
commit | 51aba60ca75f6f094951d3ffaea803072db75d29 (patch) | |
tree | 87b28756f637f4e053d94118c0edc86ec0b9cdec | |
parent | db92a780ceb130b6fa91ad866e521237c4b255b8 (diff) | |
download | Qt-51aba60ca75f6f094951d3ffaea803072db75d29.zip Qt-51aba60ca75f6f094951d3ffaea803072db75d29.tar.gz Qt-51aba60ca75f6f094951d3ffaea803072db75d29.tar.bz2 |
QNetworkDiskCache: add code snippets in documentation
should make it easier to apply a network disk cache with code snippets
now
Reviewed-by: David Boddie <dboddie@trolltech.com>
Reviewed-by: Martin Petersson <martin.petersson@trolltech.com>
-rw-r--r-- | doc/src/snippets/code/src_network_access_qnetworkdiskcache.cpp | 24 | ||||
-rw-r--r-- | src/network/access/qnetworkdiskcache.cpp | 14 |
2 files changed, 38 insertions, 0 deletions
diff --git a/doc/src/snippets/code/src_network_access_qnetworkdiskcache.cpp b/doc/src/snippets/code/src_network_access_qnetworkdiskcache.cpp new file mode 100644 index 0000000..acd3938 --- /dev/null +++ b/doc/src/snippets/code/src_network_access_qnetworkdiskcache.cpp @@ -0,0 +1,24 @@ +//! [0] +QNetworkAccessManager *manager = new QNetworkAccessManager(this); +QNetworkDiskCache *diskCache = new QNetworkDiskCache(this); +diskCache->setCacheDirectory("cacheDir"); +manager->setCache(diskCache); +//! [0] + +//! [1] +// do a normal request (preferred from network, as this is the default) +QNetworkRequest request(QUrl(QString("http://www.qtsoftware.com"))); +manager->get(request); + +// do a request preferred from cache +QNetworkRequest request2(QUrl(QString("http://www.qtsoftware.com"))); +request2.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache); +manager->get(request2); +//! [1] + +//! [2] +void replyFinished(QNetworkReply *reply) { + QVariant fromCache = reply->attribute(QNetworkRequest::SourceIsFromCacheAttribute); + qDebug() << "page from cache?" << fromCache.toBool(); +} +//! [2] diff --git a/src/network/access/qnetworkdiskcache.cpp b/src/network/access/qnetworkdiskcache.cpp index 5df6b0f..50aaa6a 100644 --- a/src/network/access/qnetworkdiskcache.cpp +++ b/src/network/access/qnetworkdiskcache.cpp @@ -81,6 +81,20 @@ QT_BEGIN_NAMESPACE use on the system to 50MB. Note you have to set the cache directory before it will work. + + A network disk cache can be enabled by: + + \snippet doc/src/snippets/code/src_network_access_qnetworkdiskcache.cpp 0 + + When sending requests, to control the preference of when to use the cache + and when to use the network, consider the following: + + \snippet doc/src/snippets/code/src_network_access_qnetworkdiskcache.cpp 1 + + To check whether the response came from the cache or from the network, the + following can be applied: + + \snippet doc/src/snippets/code/src_network_access_qnetworkdiskcache.cpp 2 */ /*! |