summaryrefslogtreecommitdiff
path: root/src/location/maps/qgeofiletilecache.cpp
diff options
context:
space:
mode:
authorPaolo Angelelli <paolo.angelelli@qt.io>2016-08-01 19:44:41 +0200
committerPaolo Angelelli <paolo.angelelli@qt.io>2016-11-08 15:19:24 +0000
commit4f192687cc07dbe5de1dbed3187d90045ed38703 (patch)
tree157d0d481f7d51215f0e197dfa3160017e820f32 /src/location/maps/qgeofiletilecache.cpp
parent219e7b84ac048ff585c36f47a1c783af9ae4e4bc (diff)
downloadqtlocation-4f192687cc07dbe5de1dbed3187d90045ed38703.tar.gz
Evict obsolete provider data on init()
During initialization, this patch makes sure that the cached tiles belong to the provider currently in use by using the file lastModified() value and comparing it against the (optional) Timestamp in the provider records. If this value is not present in the provider record, or if it is older than the newest modified file, the data is untouched. This operation is performed separately for each map id. This method isn't perfect in all use cases, though. E.g., if we are forced to shut down one of the provider and run on the hardcoded fallback, which has an older TS. These are however rare edge cases that most likely won't happen in practice (in the case above we could put the content of the hardcoded provider in the remote json files too) Change-Id: Ie29cf05c1fbc835ce4e3363fc0caa38a97800214 Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
Diffstat (limited to 'src/location/maps/qgeofiletilecache.cpp')
-rw-r--r--src/location/maps/qgeofiletilecache.cpp30
1 files changed, 29 insertions, 1 deletions
diff --git a/src/location/maps/qgeofiletilecache.cpp b/src/location/maps/qgeofiletilecache.cpp
index 6e8fa856..95bce268 100644
--- a/src/location/maps/qgeofiletilecache.cpp
+++ b/src/location/maps/qgeofiletilecache.cpp
@@ -119,7 +119,7 @@ void QGeoFileTileCache::init()
QDir::root().mkpath(directory_);
// default values
- setMaxDiskUsage(20 * 1024 * 1024);
+ setMaxDiskUsage(50 * 1024 * 1024);
setMaxMemoryUsage(3 * 1024 * 1024);
setExtraTextureUsage(6 * 1024 * 1024);
@@ -284,6 +284,34 @@ void QGeoFileTileCache::clearAll()
}
}
+void QGeoFileTileCache::clearMapId(const int mapId)
+{
+ for (const QGeoTileSpec &k : diskCache_.keys())
+ if (k.mapId() == mapId)
+ diskCache_.remove(k, true);
+ for (const QGeoTileSpec &k : memoryCache_.keys())
+ if (k.mapId() == mapId)
+ memoryCache_.remove(k);
+ for (const QGeoTileSpec &k : textureCache_.keys())
+ if (k.mapId() == mapId)
+ textureCache_.remove(k);
+
+ // TODO: It seems the cache leaves residues, like some tiles do not get picked up.
+ // After the above calls, files that shouldnt be left behind are still on disk.
+ // Do an additional pass and make sure what has to be deleted gets deleted.
+ QDir dir(directory_);
+ QStringList formats;
+ formats << QLatin1String("*.*");
+ QStringList files = dir.entryList(formats, QDir::Files);
+ qWarning() << "Old tile data detected. Cache eviction left out "<< files.size() << "tiles";
+ for (const QString &tileFileName : files) {
+ QGeoTileSpec spec = filenameToTileSpec(tileFileName);
+ if (spec.mapId() != mapId)
+ continue;
+ QFile::remove(dir.filePath(tileFileName));
+ }
+}
+
QSharedPointer<QGeoTileTexture> QGeoFileTileCache::get(const QGeoTileSpec &spec)
{
QSharedPointer<QGeoTileTexture> tt = getFromMemory(spec);