mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-21 01:42:15 -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();
|
||||
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
|
||||
} else {
|
||||
++it;
|
||||
|
|
|
|||
|
|
@ -629,11 +629,22 @@ DeckEditorSettingsPage::DeckEditorSettingsPage()
|
|||
networkCacheEdit.setValue(SettingsCache::instance().getNetworkCacheSizeInMB());
|
||||
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;
|
||||
networkCacheLayout->addStretch();
|
||||
networkCacheLayout->addWidget(&networkCacheLabel);
|
||||
networkCacheLayout->addWidget(&networkCacheEdit);
|
||||
|
||||
auto networkRedirectCacheLayout = new QHBoxLayout;
|
||||
networkRedirectCacheLayout->addStretch();
|
||||
networkRedirectCacheLayout->addWidget(&networkRedirectCacheTtlLabel);
|
||||
networkRedirectCacheLayout->addWidget(&networkRedirectCacheTtlEdit);
|
||||
|
||||
auto pixmapCacheLayout = new QHBoxLayout;
|
||||
pixmapCacheLayout->addStretch();
|
||||
pixmapCacheLayout->addWidget(&pixmapCacheLabel);
|
||||
|
|
@ -644,9 +655,10 @@ DeckEditorSettingsPage::DeckEditorSettingsPage()
|
|||
lpGeneralGrid->addWidget(&resetDownloadURLs, 0, 1);
|
||||
lpGeneralGrid->addLayout(messageListLayout, 1, 0, 1, 2);
|
||||
lpGeneralGrid->addLayout(networkCacheLayout, 2, 0, 1, 2);
|
||||
lpGeneralGrid->addLayout(pixmapCacheLayout, 3, 0, 1, 2);
|
||||
lpGeneralGrid->addWidget(&urlLinkLabel, 4, 0);
|
||||
lpGeneralGrid->addWidget(&clearDownloadedPicsButton, 4, 1);
|
||||
lpGeneralGrid->addLayout(networkRedirectCacheLayout, 3, 0, 1, 2);
|
||||
lpGeneralGrid->addLayout(pixmapCacheLayout, 4, 0, 1, 2);
|
||||
lpGeneralGrid->addWidget(&urlLinkLabel, 5, 0);
|
||||
lpGeneralGrid->addWidget(&clearDownloadedPicsButton, 5, 1);
|
||||
|
||||
// Spoiler Layout
|
||||
lpSpoilerGrid->addWidget(&mcDownloadSpoilersCheckBox, 0, 0);
|
||||
|
|
@ -662,6 +674,8 @@ DeckEditorSettingsPage::DeckEditorSettingsPage()
|
|||
SLOT(setDownloadSpoilerStatus(bool)));
|
||||
connect(&mcDownloadSpoilersCheckBox, SIGNAL(toggled(bool)), this, SLOT(setSpoilersEnabled(bool)));
|
||||
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(),
|
||||
SLOT(setNetworkCacheSizeInMB(int)));
|
||||
|
||||
|
|
@ -846,6 +860,8 @@ void DeckEditorSettingsPage::retranslateUi()
|
|||
resetDownloadURLs.setText(tr("Reset Download URLs"));
|
||||
networkCacheLabel.setText(tr("Network Cache Size:"));
|
||||
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:"));
|
||||
pixmapCacheEdit.setToolTip(tr("In-memory cache for pictures not currently on screen"));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -174,6 +174,8 @@ private:
|
|||
QPushButton *updateNowButton;
|
||||
QLabel networkCacheLabel;
|
||||
QSpinBox networkCacheEdit;
|
||||
QLabel networkRedirectCacheTtlLabel;
|
||||
QSpinBox networkRedirectCacheTtlEdit;
|
||||
QSpinBox pixmapCacheEdit;
|
||||
QLabel pixmapCacheLabel;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -221,6 +221,7 @@ SettingsCache::SettingsCache()
|
|||
pixmapCacheSize = PIXMAPCACHE_SIZE_DEFAULT;
|
||||
|
||||
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();
|
||||
|
||||
|
|
@ -657,6 +658,13 @@ void SettingsCache::setNetworkCacheSizeInMB(const int _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)
|
||||
{
|
||||
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_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 CLIENT_INFO_NOT_SET "notset"
|
||||
|
||||
|
|
@ -53,6 +58,7 @@ signals:
|
|||
void ignoreUnregisteredUserMessagesChanged();
|
||||
void pixmapCacheSizeChanged(int newSizeInMBs);
|
||||
void networkCacheSizeChanged(int newSizeInMBs);
|
||||
void redirectCacheTtlChanged(int newTtl);
|
||||
void masterVolumeChanged(int value);
|
||||
void chatMentionCompleterChanged();
|
||||
void downloadSpoilerTimeIndexChanged();
|
||||
|
|
@ -116,6 +122,7 @@ private:
|
|||
bool useTearOffMenus;
|
||||
int pixmapCacheSize;
|
||||
int networkCacheSize;
|
||||
int redirectCacheTtl;
|
||||
bool scaleCards;
|
||||
int verticalCardOverlapPercent;
|
||||
bool showMessagePopups;
|
||||
|
|
@ -360,6 +367,10 @@ public:
|
|||
{
|
||||
return networkCacheSize;
|
||||
}
|
||||
int getRedirectCacheTtl() const
|
||||
{
|
||||
return redirectCacheTtl;
|
||||
}
|
||||
bool getScaleCards() const
|
||||
{
|
||||
return scaleCards;
|
||||
|
|
@ -561,6 +572,7 @@ public slots:
|
|||
void setIgnoreUnregisteredUserMessages(QT_STATE_CHANGED_T _ignoreUnregisteredUserMessages);
|
||||
void setPixmapCacheSize(const int _pixmapCacheSize);
|
||||
void setNetworkCacheSizeInMB(const int _networkCacheSize);
|
||||
void setRedirectCacheTtl(const int _redirectCacheTtl);
|
||||
void setCardScaling(const QT_STATE_CHANGED_T _scaleCards);
|
||||
void setStackCardOverlapPercent(const int _verticalCardOverlapPercent);
|
||||
void setShowMessagePopups(const QT_STATE_CHANGED_T _showMessagePopups);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue