-
Notifications
You must be signed in to change notification settings - Fork 175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Experiment with Qt HTTP caching options #1012
base: master
Are you sure you want to change the base?
Changes from all commits
b8b9cdc
b9b801f
2723c9c
4c1cb82
2fed512
8e472fc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,7 +58,7 @@ void HTTPResourceRequest::doSend() { | |
networkRequest.setHeader(QNetworkRequest::UserAgentHeader, NetworkingConstants::VIRCADIA_USER_AGENT); | ||
|
||
if (_cacheEnabled) { | ||
networkRequest.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache); | ||
networkRequest.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferNetwork); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should theoretically fix the cachebusting issue, see the docs for more info: https://doc.qt.io/qt-5/qnetworkrequest.html#CacheLoadControl-enum |
||
} else { | ||
networkRequest.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::AlwaysNetwork); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,18 +11,42 @@ | |
|
||
#include "NetworkAccessManager.h" | ||
|
||
#include <QThreadStorage> | ||
|
||
#include "AtpReply.h" | ||
#include "ResourceCache.h" | ||
|
||
#include <QStandardPaths> | ||
#include <QThreadStorage> | ||
#include <QtNetwork/QNetworkProxy> | ||
#include <QtNetwork/QNetworkDiskCache> | ||
|
||
#include <shared/GlobalAppProperties.h> | ||
|
||
QThreadStorage<QNetworkAccessManager*> networkAccessManagers; | ||
|
||
QNetworkAccessManager& NetworkAccessManager::getInstance() { | ||
if (!networkAccessManagers.hasLocalData()) { | ||
networkAccessManagers.setLocalData(new QNetworkAccessManager()); | ||
auto networkAccessManager = new QNetworkAccessManager(); | ||
// Setup disk cache if not already | ||
if (!networkAccessManager->cache()) { | ||
QString cacheDir = qApp->property(hifi::properties::APP_LOCAL_DATA_PATH).toString(); | ||
if (cacheDir.isEmpty()) { | ||
#ifdef Q_OS_ANDROID | ||
QString cachePath = QStandardPaths::writableLocation(QStandardPaths::CacheLocation); | ||
#else | ||
QString cachePath = QStandardPaths::writableLocation(QStandardPaths::DataLocation); | ||
#endif | ||
cacheDir = !cachePath.isEmpty() ? cachePath : "interfaceCache"; | ||
} | ||
QNetworkDiskCache* cache = new QNetworkDiskCache(); | ||
cache->setMaximumCacheSize(MAXIMUM_CACHE_SIZE); | ||
cache->setCacheDirectory(cacheDir); | ||
networkAccessManager->setCache(cache); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. according to the docs: https://doc.qt.io/qt-5/qnetworkaccessmanager.html#setCache "QNetworkAccessManager by default does not have a set cache." so...I think we were forcing PreferCache above, but then...not actually setting up a cache? hopefully this new code is more correct and more performant |
||
qInfo() << "NetworkAccessManager disk cache set up at" << cacheDir | ||
<< "(size:" << MAXIMUM_CACHE_SIZE / BYTES_PER_GIGABYTES << "GB)"; | ||
} | ||
networkAccessManagers.setLocalData(networkAccessManager); | ||
} | ||
|
||
return *networkAccessManagers.localData(); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
more info below, but for some reason, it seems like we were only setting up caching for this AssetClient, not for all other requests? this code moved to NetworkAccessManager::getInstance()