What is the difference between QWebkit QWebSettings cache and QNetworkManager QNetworkDiskCache?

StackOverflow https://stackoverflow.com/questions/9096887

  •  21-04-2021
  •  | 
  •  

Question

There are web attributes (void QWebSettings::setAttribute(WebAttribute attribute, bool on)):

QWebSettings::LocalStorageDatabaseEnabled
QWebSettings::OfflineWebApplicationCacheEnabled
QWebSettings::OfflineStorageDatabaseEnabled

There are also methods:

void QWebSettings::enablePersistentStorage(const QString &path = QString())
void QWebSettings::setMaximumPagesInCache(int pages)
void QWebSettings::setObjectCacheCapacities(int cacheMinDeadCapacity, int cacheMaxDead, int totalCapacity)
void QWebSettings::setOfflineStorageDefaultQuota(qint64 maximumSize)
void QWebSettings::setOfflineStoragePath(const QString &path)
void QWebSettings::setOfflineWebApplicationCachePath(const QString &path)
void QWebSettings::setOfflineWebApplicationCacheQuota(qint64 maximumSize)

And there is QNetworkDiskCache which can be used with QNetworkAccessManager:

QNetworkDiskCache *diskCache = new QNetworkDiskCache(this);
QString location = QDesktopServices::storageLocation(QDesktopServices::CacheLocation);
diskCache->setCacheDirectory(location);
networkAccessManager->setCache(diskCache);

It has also couple of methods:

void setCacheDirectory(const QString &cacheDir)
void setMaximumCacheSize(qint64 size)

How should I implement caching properly with this confusing API?

Was it helpful?

Solution

  • The page cache referred to is the WebKit page-cache - see http://www.webkit.org/blog/427/webkit-page-cache-i-the-basics/. This is an in-memory cache to speed up Back/Forward operations in the browser.
  • setObjectCacheCapacities refers to WebKit's in-memory cache.
  • QNetworkDiskCache is, as the name suggests, a disk cache that Qt could use as an alternative to fetching resources from the network.
  • The offline web app / local storage settings are for the HTML local storage and offline web app features.

When loading pages, there are a number of levels of caching involved, from fastest to slowest:

  1. WebKit's internal in-memory caches (the page and object caches)
  2. Qt's disk cache of network resource (QNetworkDiskCache)
  3. Any local proxy caching on the user's network or system
  4. The multiple levels of caching that the site serving the page uses (eg. serving static resources from content delivery networks, Squid caches)

(3) and (4) are out of your control, (1) is enabled by default, so the only thing you potentially need to do is enable (2).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top