Closed beetleskin closed 4 years ago
Good catch!
I tested your PR without the call to request.setAttribute
and without moving the robot (only the initial area around the robot is loaded). I observed that each tile is requested four times:
However, afterwards I added the call to request.setAttribute
and I observed the exact same behavior (the diff of the prints is empty). This is even true when using CacheLoadControl::AlwaysCache
. Can you confirm this behavior?
I have no idea how we can tell Qt to always load the tiles from the cache if available. In an initial version of the rewrite of this plugin, I actually had a custom non-Qt code that loaded tiles from the cache. I'll try to find that code and to see if this solves the issue.
Nope, can't reproduce :/ For me it always loads from cache now.
I found out that the PreferNetwork cache policy respects the HTTP response header field "Cache-Control", e.g. "Cache-Control: max-age=86400". So if the cached data is older than the max-age, the web is queried. If not, the local cache is used. This change overrides this to: always use cache, if existing.
By default, QNetworkRequest uses a "prefer network" (CacheLoadControl::PreferNetwork) policy for querying data. Since we rather want to avoid downloading the same tile images, we set it to "prefer disk cache" (QNetworkRequest::PreferCache).
Details: PreferNetwork cache policy respects the HTTP response header field
Cache-Control
, e.g.Cache-Control: max-age=86400
. So if the cached data is older than the max-age, the web is queried. If not, the local cache is used. This change overrides this to: always use cache, if existing. See https://doc.qt.io/qt-5/qnetworkrequest.html for more.