made auto-deleting cache on close an option
Previously we had no disk management whatsoever, so we cleared the cache on every close just to prevent clogging up tester disk space. Now that we are implementing disk management, there are better things to do on close regarding disk cache. However, some users may still wish for the app to delete the cache on close, so it's provided as an option.
This commit is contained in:
+22
-17
@@ -13,13 +13,14 @@ DiskManager* DiskManager::instance_ = nullptr;
|
||||
DiskManager::DiskManager() :
|
||||
consumption_(0)
|
||||
{
|
||||
|
||||
// Try to load any current cache index from file
|
||||
QFile cache_index_file(QDir(GetMediaCacheLocation()).filePath("index"));
|
||||
|
||||
if (cache_index_file.open(QFile::ReadOnly)) {
|
||||
QDataStream ds(&cache_index_file);
|
||||
|
||||
ds >> consumption_;
|
||||
|
||||
while (!cache_index_file.atEnd()) {
|
||||
HashTime h;
|
||||
|
||||
@@ -30,28 +31,32 @@ DiskManager::DiskManager() :
|
||||
|
||||
disk_data_.append(h);
|
||||
}
|
||||
} else {
|
||||
qWarning() << "Failed to read cache index";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
DiskManager::~DiskManager()
|
||||
{
|
||||
// Save current cache index
|
||||
QFile cache_index_file(QDir(GetMediaCacheLocation()).filePath("index"));
|
||||
|
||||
if (cache_index_file.open(QFile::WriteOnly)) {
|
||||
QDataStream ds(&cache_index_file);
|
||||
|
||||
foreach (const HashTime& h, disk_data_) {
|
||||
ds << h.file_name;
|
||||
ds << h.hash;
|
||||
ds << h.access_time;
|
||||
ds << h.file_size;
|
||||
}
|
||||
if (Config::Current()["ClearDiskCacheOnClose"].toBool()) {
|
||||
// Clear all cache data
|
||||
QDir(GetMediaCacheLocation()).removeRecursively();
|
||||
} else {
|
||||
qWarning() << "Failed to write cache index";
|
||||
// Save current cache index
|
||||
QFile cache_index_file(QDir(GetMediaCacheLocation()).filePath("index"));
|
||||
|
||||
if (cache_index_file.open(QFile::WriteOnly)) {
|
||||
QDataStream ds(&cache_index_file);
|
||||
|
||||
ds << consumption_;
|
||||
|
||||
foreach (const HashTime& h, disk_data_) {
|
||||
ds << h.file_name;
|
||||
ds << h.hash;
|
||||
ds << h.access_time;
|
||||
ds << h.file_size;
|
||||
}
|
||||
} else {
|
||||
qWarning() << "Failed to write cache index";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user