mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-23 02:42:16 -07:00
Make redirect cache ttl a user-adjustable setting.
This commit is contained in:
parent
19e45ce929
commit
4f94aa8c5b
5 changed files with 42 additions and 4 deletions
|
|
@ -544,7 +544,7 @@ void PictureLoaderWorker::cleanStaleEntries()
|
||||||
|
|
||||||
auto it = redirectCache.begin();
|
auto it = redirectCache.begin();
|
||||||
while (it != redirectCache.end()) {
|
while (it != redirectCache.end()) {
|
||||||
if (it.value().second.addDays(CacheTTLInDays) < now) {
|
if (it.value().second.addDays(SettingsCache::instance().getRedirectCacheTtl()) < now) {
|
||||||
it = redirectCache.erase(it); // Remove stale entry
|
it = redirectCache.erase(it); // Remove stale entry
|
||||||
} else {
|
} else {
|
||||||
++it;
|
++it;
|
||||||
|
|
|
||||||
|
|
@ -629,11 +629,22 @@ DeckEditorSettingsPage::DeckEditorSettingsPage()
|
||||||
networkCacheEdit.setValue(SettingsCache::instance().getNetworkCacheSizeInMB());
|
networkCacheEdit.setValue(SettingsCache::instance().getNetworkCacheSizeInMB());
|
||||||
networkCacheEdit.setSuffix(" MB");
|
networkCacheEdit.setSuffix(" MB");
|
||||||
|
|
||||||
|
networkRedirectCacheTtlEdit.setMinimum(NETWORK_REDIRECT_CACHE_TTL_MIN);
|
||||||
|
networkRedirectCacheTtlEdit.setMaximum(NETWORK_REDIRECT_CACHE_TTL_MAX);
|
||||||
|
networkRedirectCacheTtlEdit.setSingleStep(1);
|
||||||
|
networkRedirectCacheTtlEdit.setValue(SettingsCache::instance().getRedirectCacheTtl());
|
||||||
|
networkRedirectCacheTtlEdit.setSuffix(" Days");
|
||||||
|
|
||||||
auto networkCacheLayout = new QHBoxLayout;
|
auto networkCacheLayout = new QHBoxLayout;
|
||||||
networkCacheLayout->addStretch();
|
networkCacheLayout->addStretch();
|
||||||
networkCacheLayout->addWidget(&networkCacheLabel);
|
networkCacheLayout->addWidget(&networkCacheLabel);
|
||||||
networkCacheLayout->addWidget(&networkCacheEdit);
|
networkCacheLayout->addWidget(&networkCacheEdit);
|
||||||
|
|
||||||
|
auto networkRedirectCacheLayout = new QHBoxLayout;
|
||||||
|
networkRedirectCacheLayout->addStretch();
|
||||||
|
networkRedirectCacheLayout->addWidget(&networkRedirectCacheTtlLabel);
|
||||||
|
networkRedirectCacheLayout->addWidget(&networkRedirectCacheTtlEdit);
|
||||||
|
|
||||||
auto pixmapCacheLayout = new QHBoxLayout;
|
auto pixmapCacheLayout = new QHBoxLayout;
|
||||||
pixmapCacheLayout->addStretch();
|
pixmapCacheLayout->addStretch();
|
||||||
pixmapCacheLayout->addWidget(&pixmapCacheLabel);
|
pixmapCacheLayout->addWidget(&pixmapCacheLabel);
|
||||||
|
|
@ -644,9 +655,10 @@ DeckEditorSettingsPage::DeckEditorSettingsPage()
|
||||||
lpGeneralGrid->addWidget(&resetDownloadURLs, 0, 1);
|
lpGeneralGrid->addWidget(&resetDownloadURLs, 0, 1);
|
||||||
lpGeneralGrid->addLayout(messageListLayout, 1, 0, 1, 2);
|
lpGeneralGrid->addLayout(messageListLayout, 1, 0, 1, 2);
|
||||||
lpGeneralGrid->addLayout(networkCacheLayout, 2, 0, 1, 2);
|
lpGeneralGrid->addLayout(networkCacheLayout, 2, 0, 1, 2);
|
||||||
lpGeneralGrid->addLayout(pixmapCacheLayout, 3, 0, 1, 2);
|
lpGeneralGrid->addLayout(networkRedirectCacheLayout, 3, 0, 1, 2);
|
||||||
lpGeneralGrid->addWidget(&urlLinkLabel, 4, 0);
|
lpGeneralGrid->addLayout(pixmapCacheLayout, 4, 0, 1, 2);
|
||||||
lpGeneralGrid->addWidget(&clearDownloadedPicsButton, 4, 1);
|
lpGeneralGrid->addWidget(&urlLinkLabel, 5, 0);
|
||||||
|
lpGeneralGrid->addWidget(&clearDownloadedPicsButton, 5, 1);
|
||||||
|
|
||||||
// Spoiler Layout
|
// Spoiler Layout
|
||||||
lpSpoilerGrid->addWidget(&mcDownloadSpoilersCheckBox, 0, 0);
|
lpSpoilerGrid->addWidget(&mcDownloadSpoilersCheckBox, 0, 0);
|
||||||
|
|
@ -662,6 +674,8 @@ DeckEditorSettingsPage::DeckEditorSettingsPage()
|
||||||
SLOT(setDownloadSpoilerStatus(bool)));
|
SLOT(setDownloadSpoilerStatus(bool)));
|
||||||
connect(&mcDownloadSpoilersCheckBox, SIGNAL(toggled(bool)), this, SLOT(setSpoilersEnabled(bool)));
|
connect(&mcDownloadSpoilersCheckBox, SIGNAL(toggled(bool)), this, SLOT(setSpoilersEnabled(bool)));
|
||||||
connect(&pixmapCacheEdit, SIGNAL(valueChanged(int)), &SettingsCache::instance(), SLOT(setPixmapCacheSize(int)));
|
connect(&pixmapCacheEdit, SIGNAL(valueChanged(int)), &SettingsCache::instance(), SLOT(setPixmapCacheSize(int)));
|
||||||
|
connect(&networkRedirectCacheTtlEdit, SIGNAL(valueChanged(int)), &SettingsCache::instance(),
|
||||||
|
SLOT(setNetworkRedirectCacheTtl(int)));
|
||||||
connect(&networkCacheEdit, SIGNAL(valueChanged(int)), &SettingsCache::instance(),
|
connect(&networkCacheEdit, SIGNAL(valueChanged(int)), &SettingsCache::instance(),
|
||||||
SLOT(setNetworkCacheSizeInMB(int)));
|
SLOT(setNetworkCacheSizeInMB(int)));
|
||||||
|
|
||||||
|
|
@ -846,6 +860,8 @@ void DeckEditorSettingsPage::retranslateUi()
|
||||||
resetDownloadURLs.setText(tr("Reset Download URLs"));
|
resetDownloadURLs.setText(tr("Reset Download URLs"));
|
||||||
networkCacheLabel.setText(tr("Network Cache Size:"));
|
networkCacheLabel.setText(tr("Network Cache Size:"));
|
||||||
networkCacheEdit.setToolTip(tr("On-disk cache for downloaded pictures"));
|
networkCacheEdit.setToolTip(tr("On-disk cache for downloaded pictures"));
|
||||||
|
networkRedirectCacheTtlLabel.setText(tr("Redirect cache expiration time in days"));
|
||||||
|
networkRedirectCacheTtlEdit.setToolTip(tr("How long cached redirects for urls are valid for."));
|
||||||
pixmapCacheLabel.setText(tr("Picture cache size:"));
|
pixmapCacheLabel.setText(tr("Picture cache size:"));
|
||||||
pixmapCacheEdit.setToolTip(tr("In-memory cache for pictures not currently on screen"));
|
pixmapCacheEdit.setToolTip(tr("In-memory cache for pictures not currently on screen"));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -174,6 +174,8 @@ private:
|
||||||
QPushButton *updateNowButton;
|
QPushButton *updateNowButton;
|
||||||
QLabel networkCacheLabel;
|
QLabel networkCacheLabel;
|
||||||
QSpinBox networkCacheEdit;
|
QSpinBox networkCacheEdit;
|
||||||
|
QLabel networkRedirectCacheTtlLabel;
|
||||||
|
QSpinBox networkRedirectCacheTtlEdit;
|
||||||
QSpinBox pixmapCacheEdit;
|
QSpinBox pixmapCacheEdit;
|
||||||
QLabel pixmapCacheLabel;
|
QLabel pixmapCacheLabel;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -221,6 +221,7 @@ SettingsCache::SettingsCache()
|
||||||
pixmapCacheSize = PIXMAPCACHE_SIZE_DEFAULT;
|
pixmapCacheSize = PIXMAPCACHE_SIZE_DEFAULT;
|
||||||
|
|
||||||
networkCacheSize = settings->value("personal/networkCacheSize", NETWORK_CACHE_SIZE_DEFAULT).toInt();
|
networkCacheSize = settings->value("personal/networkCacheSize", NETWORK_CACHE_SIZE_DEFAULT).toInt();
|
||||||
|
redirectCacheTtl = settings->value("personal/redirectCacheTtl", NETWORK_REDIRECT_CACHE_TTL_DEFAULT).toInt();
|
||||||
|
|
||||||
picDownload = settings->value("personal/picturedownload", true).toBool();
|
picDownload = settings->value("personal/picturedownload", true).toBool();
|
||||||
|
|
||||||
|
|
@ -657,6 +658,13 @@ void SettingsCache::setNetworkCacheSizeInMB(const int _networkCacheSize)
|
||||||
emit networkCacheSizeChanged(networkCacheSize);
|
emit networkCacheSizeChanged(networkCacheSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SettingsCache::setRedirectCacheTtl(const int _redirectCacheTtl)
|
||||||
|
{
|
||||||
|
redirectCacheTtl = _redirectCacheTtl;
|
||||||
|
settings->setValue("personal/redirectCacheSize", redirectCacheTtl);
|
||||||
|
emit redirectCacheTtlChanged(redirectCacheTtl);
|
||||||
|
}
|
||||||
|
|
||||||
void SettingsCache::setClientID(const QString &_clientID)
|
void SettingsCache::setClientID(const QString &_clientID)
|
||||||
{
|
{
|
||||||
clientID = _clientID;
|
clientID = _clientID;
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,11 @@ constexpr int NETWORK_CACHE_SIZE_DEFAULT = 1024 * 4; // 4 GB
|
||||||
constexpr int NETWORK_CACHE_SIZE_MIN = 1; // 1 MB
|
constexpr int NETWORK_CACHE_SIZE_MIN = 1; // 1 MB
|
||||||
constexpr int NETWORK_CACHE_SIZE_MAX = 1024 * 1024; // 1 TB
|
constexpr int NETWORK_CACHE_SIZE_MAX = 1024 * 1024; // 1 TB
|
||||||
|
|
||||||
|
// In Days
|
||||||
|
#define NETWORK_REDIRECT_CACHE_TTL_DEFAULT 30
|
||||||
|
#define NETWORK_REDIRECT_CACHE_TTL_MIN 1
|
||||||
|
#define NETWORK_REDIRECT_CACHE_TTL_MAX 90
|
||||||
|
|
||||||
#define DEFAULT_LANG_NAME "English"
|
#define DEFAULT_LANG_NAME "English"
|
||||||
#define CLIENT_INFO_NOT_SET "notset"
|
#define CLIENT_INFO_NOT_SET "notset"
|
||||||
|
|
||||||
|
|
@ -53,6 +58,7 @@ signals:
|
||||||
void ignoreUnregisteredUserMessagesChanged();
|
void ignoreUnregisteredUserMessagesChanged();
|
||||||
void pixmapCacheSizeChanged(int newSizeInMBs);
|
void pixmapCacheSizeChanged(int newSizeInMBs);
|
||||||
void networkCacheSizeChanged(int newSizeInMBs);
|
void networkCacheSizeChanged(int newSizeInMBs);
|
||||||
|
void redirectCacheTtlChanged(int newTtl);
|
||||||
void masterVolumeChanged(int value);
|
void masterVolumeChanged(int value);
|
||||||
void chatMentionCompleterChanged();
|
void chatMentionCompleterChanged();
|
||||||
void downloadSpoilerTimeIndexChanged();
|
void downloadSpoilerTimeIndexChanged();
|
||||||
|
|
@ -116,6 +122,7 @@ private:
|
||||||
bool useTearOffMenus;
|
bool useTearOffMenus;
|
||||||
int pixmapCacheSize;
|
int pixmapCacheSize;
|
||||||
int networkCacheSize;
|
int networkCacheSize;
|
||||||
|
int redirectCacheTtl;
|
||||||
bool scaleCards;
|
bool scaleCards;
|
||||||
int verticalCardOverlapPercent;
|
int verticalCardOverlapPercent;
|
||||||
bool showMessagePopups;
|
bool showMessagePopups;
|
||||||
|
|
@ -360,6 +367,10 @@ public:
|
||||||
{
|
{
|
||||||
return networkCacheSize;
|
return networkCacheSize;
|
||||||
}
|
}
|
||||||
|
int getRedirectCacheTtl() const
|
||||||
|
{
|
||||||
|
return redirectCacheTtl;
|
||||||
|
}
|
||||||
bool getScaleCards() const
|
bool getScaleCards() const
|
||||||
{
|
{
|
||||||
return scaleCards;
|
return scaleCards;
|
||||||
|
|
@ -561,6 +572,7 @@ public slots:
|
||||||
void setIgnoreUnregisteredUserMessages(QT_STATE_CHANGED_T _ignoreUnregisteredUserMessages);
|
void setIgnoreUnregisteredUserMessages(QT_STATE_CHANGED_T _ignoreUnregisteredUserMessages);
|
||||||
void setPixmapCacheSize(const int _pixmapCacheSize);
|
void setPixmapCacheSize(const int _pixmapCacheSize);
|
||||||
void setNetworkCacheSizeInMB(const int _networkCacheSize);
|
void setNetworkCacheSizeInMB(const int _networkCacheSize);
|
||||||
|
void setRedirectCacheTtl(const int _redirectCacheTtl);
|
||||||
void setCardScaling(const QT_STATE_CHANGED_T _scaleCards);
|
void setCardScaling(const QT_STATE_CHANGED_T _scaleCards);
|
||||||
void setStackCardOverlapPercent(const int _verticalCardOverlapPercent);
|
void setStackCardOverlapPercent(const int _verticalCardOverlapPercent);
|
||||||
void setShowMessagePopups(const QT_STATE_CHANGED_T _showMessagePopups);
|
void setShowMessagePopups(const QT_STATE_CHANGED_T _showMessagePopups);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue