Hi all,
I can't manage to make the cache work with WNAM.
Here is what I did so far :
MyNetworkManager* manager = new MyNetworkManager(parent);
QNetworkDiskCache* diskCache = new QNetworkDiskCache(parent);
diskCache->setCacheDirectory(dataPath);
diskCache->setMaximumCacheSize(5*1024*1024); // 5Mo
manager->setCache(diskCache);
MyNetworkManager* manager = new MyNetworkManager(parent);
QNetworkDiskCache* diskCache = new QNetworkDiskCache(parent);
QString dataPath = QDesktopServices::storageLocation(QDesktopServices::CacheLocation);
diskCache->setCacheDirectory(dataPath);
diskCache->setMaximumCacheSize(5*1024*1024); // 5Mo
manager->setCache(diskCache);
To copy to clipboard, switch view to plain text mode
MyNetworkManager is very simple and redefines :
QNetworkReply *
MyNetworkManager
::createRequest( Operation op,
const QNetworkRequest
& req,
QIODevice * outgoingData
){
QNetworkRequest request(req);
request.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache);
return QNetworkAccessManager::createRequest(op, request, outgoingData);
}
QNetworkReply *
MyNetworkManager::createRequest( Operation op, const QNetworkRequest & req, QIODevice * outgoingData)
{
QNetworkRequest request(req);
request.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache);
return QNetworkAccessManager::createRequest(op, request, outgoingData);
}
To copy to clipboard, switch view to plain text mode
I use this manager in a Symbian QML application. I can see all requests goes through my createRequest function, which is fine.
I can also see that .cache files are created in the cache directory and they contains the responses data.
However, when I switch the internet connection off, the manager does not return cached data.
What am I doing wrong here ? Can somebody point me on a working exemple of using cache with QNAM (preferably with QML but pure Qt is also ok).
Thank you for your help !
Rémy
Bookmarks