From e5755e131952ab5c3c8dd0fd6a88dbaa7148898a Mon Sep 17 00:00:00 2001 From: Benjamin C Meyer Date: Wed, 29 Apr 2009 11:15:25 -0400 Subject: Fix QNetworkDiskCache to expire the oldest files first. When expiring cache files use a QMultiMap, when using a QMap not all files are put into the map because often many files (downloaded or updated at the same time) will have the same creation QDateTime and so only one will go into the QMap who's key is QDateTime. Reviewed-By: Thiago Macieira Reviewed-By: Peter Hartmann --- src/network/access/qnetworkdiskcache.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/network/access/qnetworkdiskcache.cpp b/src/network/access/qnetworkdiskcache.cpp index 892929e6e2..44a82988d0 100644 --- a/src/network/access/qnetworkdiskcache.cpp +++ b/src/network/access/qnetworkdiskcache.cpp @@ -494,21 +494,21 @@ qint64 QNetworkDiskCache::expire() QDir::Filters filters = QDir::AllDirs | QDir:: Files | QDir::NoDotAndDotDot; QDirIterator it(cacheDirectory(), filters, QDirIterator::Subdirectories); - QMap cacheItems; + QMultiMap cacheItems; qint64 totalSize = 0; while (it.hasNext()) { QString path = it.next(); QFileInfo info = it.fileInfo(); QString fileName = info.fileName(); if (fileName.endsWith(CACHE_POSTFIX) && fileName.startsWith(CACHE_PREFIX)) { - cacheItems[info.created()] = path; + cacheItems.insert(info.created(), path); totalSize += info.size(); } } int removedFiles = 0; qint64 goal = (maximumCacheSize() * 9) / 10; - QMap::const_iterator i = cacheItems.constBegin(); + QMultiMap::const_iterator i = cacheItems.constBegin(); while (i != cacheItems.constEnd()) { if (totalSize < goal) break; -- cgit v1.2.3