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:
itsmattkc
2020-01-09 21:00:04 +11:00
parent 9c2c384833
commit 362cb9daef
7 changed files with 48 additions and 27 deletions
+1
View File
@@ -76,6 +76,7 @@ void Config::SetDefaults()
config_map_["DiskCachePath"] = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation);
config_map_["DiskCacheSize"] = 20.0;
config_map_["ClearDiskCacheOnClose"] = false;
config_map_["DefaultSequenceWidth"] = 1920;
config_map_["DefaultSequenceHeight"] = 1080;
+6
View File
@@ -43,6 +43,7 @@
#include "project/item/footage/footage.h"
#include "project/item/sequence/sequence.h"
#include "render/colormanager.h"
#include "render/diskmanager.h"
#include "task/import/import.h"
#include "task/taskmanager.h"
#include "ui/style/style.h"
@@ -129,6 +130,8 @@ void Core::Stop()
AudioManager::DestroyInstance();
DiskManager::DestroyInstance();
NodeFactory::Destroy();
delete main_window_;
@@ -376,6 +379,9 @@ void Core::StartGUI(bool full_screen)
// Initialize audio service
AudioManager::CreateInstance();
// Initialize disk service
DiskManager::CreateInstance();
// Connect the PanelFocusManager to the application's focus change signal
connect(qApp,
SIGNAL(focusChanged(QWidget*, QWidget*)),
@@ -42,6 +42,12 @@ PreferencesDiskTab::PreferencesDiskTab()
connect(clear_cache_btn, &QPushButton::clicked, this, &PreferencesDiskTab::ClearDiskCache);
layout->addWidget(clear_cache_btn, row, 1, 1, 2);
row++;
clear_disk_cache_ = new QCheckBox(tr("Automatically clear disk cache on close"));
clear_disk_cache_->setChecked(Config::Current()["ClearDiskCacheOnClose"].toBool());
layout->addWidget(clear_disk_cache_, row, 1, 1, 2);
outer_layout->addStretch();
}
@@ -49,6 +55,7 @@ void PreferencesDiskTab::Accept()
{
Config::Current()["DiskCachePath"] = disk_cache_location_->text();
Config::Current()["DiskCacheSize"] = maximum_cache_slider_->GetValue();
Config::Current()["ClearDiskCacheOnClose"] = clear_disk_cache_->isChecked();
}
void PreferencesDiskTab::DiskCacheLineEditChanged()
@@ -1,6 +1,7 @@
#ifndef PREFERENCESDISKTAB_H
#define PREFERENCESDISKTAB_H
#include <QCheckBox>
#include <QLineEdit>
#include "preferencestab.h"
@@ -19,6 +20,8 @@ private:
FloatSlider* maximum_cache_slider_;
QCheckBox* clear_disk_cache_;
private slots:
void DiskCacheLineEditChanged();
@@ -28,6 +28,7 @@
#include <QtMath>
#include "common/timecodefunctions.h"
#include "render/diskmanager.h"
#include "render/pixelservice.h"
#include "videorenderworker.h"
@@ -181,6 +182,8 @@ const char *VideoRenderBackend::GetCachedFrame(const rational &time)
auto in = OIIO::ImageInput::open(fn.toStdString());
if (in) {
DiskManager::instance()->Accessed(frame_hash);
in->read_image(PixelService::GetPixelFormatInfo(params_.format()).oiio_desc, cache_frame_load_buffer_.data());
in->close();
@@ -244,6 +247,11 @@ void VideoRenderBackend::ThreadCompletedDownload(NodeDependency dep, qint64 job_
SetFrameHash(dep, hash, job_time);
// Register frame with the disk manager
if (operating_mode_ & VideoRenderWorker::kDownloadOnly) {
DiskManager::instance()->CreatedFile(frame_cache()->CachePathName(hash), hash);
}
QList<rational> hashes_with_time = frame_cache()->FramesWithHash(hash);
foreach (const rational& t, hashes_with_time) {
+22 -17
View File
@@ -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";
}
}
}
+1 -10
View File
@@ -143,20 +143,11 @@ void MainWindow::ProjectOpen(Project* p)
SetDefaultLayout();
}
// FIXME: Test code
#include <QDir>
#include "common/filefunctions.h"
// End test code
void MainWindow::closeEvent(QCloseEvent *e)
{
PanelManager::instance()->DeleteAllPanels();
// FIXME: Test code - We have no cache management and the cache is very much testing only, so we delete it on close
// as to not clog up HDD space
QDir(GetMediaCacheLocation()).removeRecursively();
//QDir(GetMediaIndexLocation()).removeRecursively();
// End test code
QMainWindow::closeEvent(e);
}