From 8192a48bc589de8c2223693054c4c59355a9db5c Mon Sep 17 00:00:00 2001 From: MaysWind Date: Sat, 28 Feb 2026 21:36:00 +0800 Subject: [PATCH] support setting exchange rate cache expiration time --- src/DesktopApp.vue | 1 + src/MobileApp.vue | 1 + src/core/setting.ts | 2 + src/locales/de.json | 5 +- src/locales/en.json | 5 +- src/locales/es.json | 5 +- src/locales/fr.json | 5 +- src/locales/it.json | 5 +- src/locales/ja.json | 5 +- src/locales/kn.json | 5 +- src/locales/ko.json | 5 +- src/locales/nl.json | 5 +- src/locales/pt_BR.json | 5 +- src/locales/ru.json | 5 +- src/locales/sl.json | 5 +- src/locales/ta.json | 5 +- src/locales/th.json | 5 +- src/locales/tr.json | 5 +- src/locales/uk.json | 5 +- src/locales/vi.json | 5 +- src/locales/zh_Hans.json | 5 +- src/locales/zh_Hant.json | 5 +- src/stores/exchangeRates.ts | 46 +++++-- src/stores/setting.ts | 6 + .../AppBrowserCacheSettingPageBase.ts | 112 ++++++++++++++++++ .../tabs/AppBrowserCacheSettingTab.vue | 30 ++++- .../settings/BrowserCacheSettingPage.vue | 40 ++++++- 27 files changed, 303 insertions(+), 30 deletions(-) create mode 100644 src/views/base/settings/AppBrowserCacheSettingPageBase.ts diff --git a/src/DesktopApp.vue b/src/DesktopApp.vue index 248657da..8b3d0025 100644 --- a/src/DesktopApp.vue +++ b/src/DesktopApp.vue @@ -114,6 +114,7 @@ window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', fun let localeDefaultSettings = initLocale(userStore.currentUserLanguage, settingsStore.appSettings.timeZone); settingsStore.updateLocalizedDefaultSettings(localeDefaultSettings); +exchangeRatesStore.removeExpiredExchangeRates(true); setExpenseAndIncomeAmountColor(userStore.currentUserExpenseAmountColor, userStore.currentUserIncomeAmountColor); diff --git a/src/MobileApp.vue b/src/MobileApp.vue index 0d883afa..302dc496 100644 --- a/src/MobileApp.vue +++ b/src/MobileApp.vue @@ -221,6 +221,7 @@ watch(currentNotificationContent, (newValue) => { let localeDefaultSettings = initLocale(userStore.currentUserLanguage, settingsStore.appSettings.timeZone); settingsStore.updateLocalizedDefaultSettings(localeDefaultSettings); +exchangeRatesStore.removeExpiredExchangeRates(true); setExpenseAndIncomeAmountColor(userStore.currentUserExpenseAmountColor, userStore.currentUserIncomeAmountColor); diff --git a/src/core/setting.ts b/src/core/setting.ts index c136259b..62ce9e8a 100644 --- a/src/core/setting.ts +++ b/src/core/setting.ts @@ -64,6 +64,7 @@ export interface ApplicationSettings extends BaseApplicationSetting { currencySortByInExchangeRatesPage: number; // Browser Cache Settings mapCacheExpiration: number, + exchangeRatesDataCacheExpiration: number, // Statistics Settings statistics: { defaultChartDataType: number; @@ -191,6 +192,7 @@ export const DEFAULT_APPLICATION_SETTINGS: ApplicationSettings = { currencySortByInExchangeRatesPage: CurrencySortingType.Default.type, // Browser Cache Settings mapCacheExpiration: -1, + exchangeRatesDataCacheExpiration: 0, // Statistics Settings statistics: { defaultChartDataType: ChartDataType.Default.type, diff --git a/src/locales/de.json b/src/locales/de.json index ad99e9ee..2219aa82 100644 --- a/src/locales/de.json +++ b/src/locales/de.json @@ -2514,11 +2514,14 @@ "Others": "Others", "Cache Expiration Time": "Cache Expiration Time", "Cache Expiration for Map Data": "Cache Expiration for Map Data", - "Disable Map Cache": "Disable Map Cache", + "Cache Expiration for Exchange Rates Data": "Cache Expiration for Exchange Rates Data", + "Disable Cache": "Disable Cache", "Clear All File Cache": "Clear All File Cache", "Are you sure you want to clear all file cache?": "Are you sure you want to clear all file cache?", "Clear Map Data Cache": "Clear Map Data Cache", "Are you sure you want to clear map data cache?": "Are you sure you want to clear map data cache?", + "Clear Exchange Rates Data Cache": "Clear Exchange Rates Data Cache", + "Are you sure you want to clear exchange rates data cache?": "Are you sure you want to clear exchange rates data cache?", "Are you sure you want to re-login?": "Sind Sie sicher, dass Sie sich erneut anmelden möchten?", "Exchange Rates Data": "Wechselkursdaten", "User Custom": "User Custom", diff --git a/src/locales/en.json b/src/locales/en.json index 758bc120..cb198c3c 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -2514,11 +2514,14 @@ "Others": "Others", "Cache Expiration Time": "Cache Expiration Time", "Cache Expiration for Map Data": "Cache Expiration for Map Data", - "Disable Map Cache": "Disable Map Cache", + "Cache Expiration for Exchange Rates Data": "Cache Expiration for Exchange Rates Data", + "Disable Cache": "Disable Cache", "Clear All File Cache": "Clear All File Cache", "Are you sure you want to clear all file cache?": "Are you sure you want to clear all file cache?", "Clear Map Data Cache": "Clear Map Data Cache", "Are you sure you want to clear map data cache?": "Are you sure you want to clear map data cache?", + "Clear Exchange Rates Data Cache": "Clear Exchange Rates Data Cache", + "Are you sure you want to clear exchange rates data cache?": "Are you sure you want to clear exchange rates data cache?", "Are you sure you want to re-login?": "Are you sure you want to re-login?", "Exchange Rates Data": "Exchange Rates Data", "User Custom": "User Custom", diff --git a/src/locales/es.json b/src/locales/es.json index 39549d67..b6080281 100644 --- a/src/locales/es.json +++ b/src/locales/es.json @@ -2514,11 +2514,14 @@ "Others": "Others", "Cache Expiration Time": "Cache Expiration Time", "Cache Expiration for Map Data": "Cache Expiration for Map Data", - "Disable Map Cache": "Disable Map Cache", + "Cache Expiration for Exchange Rates Data": "Cache Expiration for Exchange Rates Data", + "Disable Cache": "Disable Cache", "Clear All File Cache": "Clear All File Cache", "Are you sure you want to clear all file cache?": "Are you sure you want to clear all file cache?", "Clear Map Data Cache": "Clear Map Data Cache", "Are you sure you want to clear map data cache?": "Are you sure you want to clear map data cache?", + "Clear Exchange Rates Data Cache": "Clear Exchange Rates Data Cache", + "Are you sure you want to clear exchange rates data cache?": "Are you sure you want to clear exchange rates data cache?", "Are you sure you want to re-login?": "¿Seguro que deseas volver a iniciar sesión?", "Exchange Rates Data": "Tipos de Cambio", "User Custom": "User Custom", diff --git a/src/locales/fr.json b/src/locales/fr.json index dd3862b4..6f7bf0ab 100644 --- a/src/locales/fr.json +++ b/src/locales/fr.json @@ -2514,11 +2514,14 @@ "Others": "Others", "Cache Expiration Time": "Cache Expiration Time", "Cache Expiration for Map Data": "Cache Expiration for Map Data", - "Disable Map Cache": "Disable Map Cache", + "Cache Expiration for Exchange Rates Data": "Cache Expiration for Exchange Rates Data", + "Disable Cache": "Disable Cache", "Clear All File Cache": "Clear All File Cache", "Are you sure you want to clear all file cache?": "Are you sure you want to clear all file cache?", "Clear Map Data Cache": "Clear Map Data Cache", "Are you sure you want to clear map data cache?": "Are you sure you want to clear map data cache?", + "Clear Exchange Rates Data Cache": "Clear Exchange Rates Data Cache", + "Are you sure you want to clear exchange rates data cache?": "Are you sure you want to clear exchange rates data cache?", "Are you sure you want to re-login?": "Êtes-vous sûr de vouloir vous reconnecter ?", "Exchange Rates Data": "Données de taux de change", "User Custom": "Personnalisé utilisateur", diff --git a/src/locales/it.json b/src/locales/it.json index faa5cded..48b96c49 100644 --- a/src/locales/it.json +++ b/src/locales/it.json @@ -2514,11 +2514,14 @@ "Others": "Others", "Cache Expiration Time": "Cache Expiration Time", "Cache Expiration for Map Data": "Cache Expiration for Map Data", - "Disable Map Cache": "Disable Map Cache", + "Cache Expiration for Exchange Rates Data": "Cache Expiration for Exchange Rates Data", + "Disable Cache": "Disable Cache", "Clear All File Cache": "Clear All File Cache", "Are you sure you want to clear all file cache?": "Are you sure you want to clear all file cache?", "Clear Map Data Cache": "Clear Map Data Cache", "Are you sure you want to clear map data cache?": "Are you sure you want to clear map data cache?", + "Clear Exchange Rates Data Cache": "Clear Exchange Rates Data Cache", + "Are you sure you want to clear exchange rates data cache?": "Are you sure you want to clear exchange rates data cache?", "Are you sure you want to re-login?": "Sei sicuro di voler accedere di nuovo?", "Exchange Rates Data": "Dati tassi di cambio", "User Custom": "User Custom", diff --git a/src/locales/ja.json b/src/locales/ja.json index 4c46cc7a..d67fc5a2 100644 --- a/src/locales/ja.json +++ b/src/locales/ja.json @@ -2514,11 +2514,14 @@ "Others": "Others", "Cache Expiration Time": "Cache Expiration Time", "Cache Expiration for Map Data": "Cache Expiration for Map Data", - "Disable Map Cache": "Disable Map Cache", + "Cache Expiration for Exchange Rates Data": "Cache Expiration for Exchange Rates Data", + "Disable Cache": "Disable Cache", "Clear All File Cache": "Clear All File Cache", "Are you sure you want to clear all file cache?": "Are you sure you want to clear all file cache?", "Clear Map Data Cache": "Clear Map Data Cache", "Are you sure you want to clear map data cache?": "Are you sure you want to clear map data cache?", + "Clear Exchange Rates Data Cache": "Clear Exchange Rates Data Cache", + "Are you sure you want to clear exchange rates data cache?": "Are you sure you want to clear exchange rates data cache?", "Are you sure you want to re-login?": "再ログインしますか?", "Exchange Rates Data": "為替レートデータ", "User Custom": "User Custom", diff --git a/src/locales/kn.json b/src/locales/kn.json index 7b2cbe4a..62b6532f 100644 --- a/src/locales/kn.json +++ b/src/locales/kn.json @@ -2514,11 +2514,14 @@ "Others": "Others", "Cache Expiration Time": "Cache Expiration Time", "Cache Expiration for Map Data": "Cache Expiration for Map Data", - "Disable Map Cache": "Disable Map Cache", + "Cache Expiration for Exchange Rates Data": "Cache Expiration for Exchange Rates Data", + "Disable Cache": "Disable Cache", "Clear All File Cache": "Clear All File Cache", "Are you sure you want to clear all file cache?": "Are you sure you want to clear all file cache?", "Clear Map Data Cache": "Clear Map Data Cache", "Are you sure you want to clear map data cache?": "Are you sure you want to clear map data cache?", + "Clear Exchange Rates Data Cache": "Clear Exchange Rates Data Cache", + "Are you sure you want to clear exchange rates data cache?": "Are you sure you want to clear exchange rates data cache?", "Are you sure you want to re-login?": "ಮತ್ತೆ ಲಾಗಿನ್ ಮಾಡಲು ನೀವು ಖಚಿತವೇ?", "Exchange Rates Data": "ವಿನಿಮಯ ದರ ಡೇಟಾ", "User Custom": "ಬಳಕೆದಾರ ಕಸ್ಟಮ್", diff --git a/src/locales/ko.json b/src/locales/ko.json index 0dc50b07..2ebad810 100644 --- a/src/locales/ko.json +++ b/src/locales/ko.json @@ -2514,11 +2514,14 @@ "Others": "Others", "Cache Expiration Time": "Cache Expiration Time", "Cache Expiration for Map Data": "Cache Expiration for Map Data", - "Disable Map Cache": "Disable Map Cache", + "Cache Expiration for Exchange Rates Data": "Cache Expiration for Exchange Rates Data", + "Disable Cache": "Disable Cache", "Clear All File Cache": "Clear All File Cache", "Are you sure you want to clear all file cache?": "Are you sure you want to clear all file cache?", "Clear Map Data Cache": "Clear Map Data Cache", "Are you sure you want to clear map data cache?": "Are you sure you want to clear map data cache?", + "Clear Exchange Rates Data Cache": "Clear Exchange Rates Data Cache", + "Are you sure you want to clear exchange rates data cache?": "Are you sure you want to clear exchange rates data cache?", "Are you sure you want to re-login?": "다시 로그인하시겠습니까?", "Exchange Rates Data": "환율 데이터", "User Custom": "사용자 정의", diff --git a/src/locales/nl.json b/src/locales/nl.json index f84798a0..3598d1c3 100644 --- a/src/locales/nl.json +++ b/src/locales/nl.json @@ -2514,11 +2514,14 @@ "Others": "Others", "Cache Expiration Time": "Cache Expiration Time", "Cache Expiration for Map Data": "Cache Expiration for Map Data", - "Disable Map Cache": "Disable Map Cache", + "Cache Expiration for Exchange Rates Data": "Cache Expiration for Exchange Rates Data", + "Disable Cache": "Disable Cache", "Clear All File Cache": "Clear All File Cache", "Are you sure you want to clear all file cache?": "Are you sure you want to clear all file cache?", "Clear Map Data Cache": "Clear Map Data Cache", "Are you sure you want to clear map data cache?": "Are you sure you want to clear map data cache?", + "Clear Exchange Rates Data Cache": "Clear Exchange Rates Data Cache", + "Are you sure you want to clear exchange rates data cache?": "Are you sure you want to clear exchange rates data cache?", "Are you sure you want to re-login?": "Weet je zeker dat je opnieuw wilt inloggen?", "Exchange Rates Data": "Wisselkoersgegevens", "User Custom": "Gebruiker aangepast", diff --git a/src/locales/pt_BR.json b/src/locales/pt_BR.json index ee4c60ce..7566af4f 100644 --- a/src/locales/pt_BR.json +++ b/src/locales/pt_BR.json @@ -2514,11 +2514,14 @@ "Others": "Others", "Cache Expiration Time": "Cache Expiration Time", "Cache Expiration for Map Data": "Cache Expiration for Map Data", - "Disable Map Cache": "Disable Map Cache", + "Cache Expiration for Exchange Rates Data": "Cache Expiration for Exchange Rates Data", + "Disable Cache": "Disable Cache", "Clear All File Cache": "Clear All File Cache", "Are you sure you want to clear all file cache?": "Are you sure you want to clear all file cache?", "Clear Map Data Cache": "Clear Map Data Cache", "Are you sure you want to clear map data cache?": "Are you sure you want to clear map data cache?", + "Clear Exchange Rates Data Cache": "Clear Exchange Rates Data Cache", + "Are you sure you want to clear exchange rates data cache?": "Are you sure you want to clear exchange rates data cache?", "Are you sure you want to re-login?": "Tem certeza de que deseja fazer login novamente?", "Exchange Rates Data": "Dados de Taxas de Câmbio", "User Custom": "Personalização do Usuário", diff --git a/src/locales/ru.json b/src/locales/ru.json index c7e09932..b1d42430 100644 --- a/src/locales/ru.json +++ b/src/locales/ru.json @@ -2514,11 +2514,14 @@ "Others": "Others", "Cache Expiration Time": "Cache Expiration Time", "Cache Expiration for Map Data": "Cache Expiration for Map Data", - "Disable Map Cache": "Disable Map Cache", + "Cache Expiration for Exchange Rates Data": "Cache Expiration for Exchange Rates Data", + "Disable Cache": "Disable Cache", "Clear All File Cache": "Clear All File Cache", "Are you sure you want to clear all file cache?": "Are you sure you want to clear all file cache?", "Clear Map Data Cache": "Clear Map Data Cache", "Are you sure you want to clear map data cache?": "Are you sure you want to clear map data cache?", + "Clear Exchange Rates Data Cache": "Clear Exchange Rates Data Cache", + "Are you sure you want to clear exchange rates data cache?": "Are you sure you want to clear exchange rates data cache?", "Are you sure you want to re-login?": "Вы уверены, что хотите войти снова?", "Exchange Rates Data": "Данные о курсах валют", "User Custom": "Пользовательские настройки", diff --git a/src/locales/sl.json b/src/locales/sl.json index 770525fe..85b33ff1 100644 --- a/src/locales/sl.json +++ b/src/locales/sl.json @@ -2514,11 +2514,14 @@ "Others": "Others", "Cache Expiration Time": "Cache Expiration Time", "Cache Expiration for Map Data": "Cache Expiration for Map Data", - "Disable Map Cache": "Disable Map Cache", + "Cache Expiration for Exchange Rates Data": "Cache Expiration for Exchange Rates Data", + "Disable Cache": "Disable Cache", "Clear All File Cache": "Clear All File Cache", "Are you sure you want to clear all file cache?": "Are you sure you want to clear all file cache?", "Clear Map Data Cache": "Clear Map Data Cache", "Are you sure you want to clear map data cache?": "Are you sure you want to clear map data cache?", + "Clear Exchange Rates Data Cache": "Clear Exchange Rates Data Cache", + "Are you sure you want to clear exchange rates data cache?": "Are you sure you want to clear exchange rates data cache?", "Are you sure you want to re-login?": "Ali ste prepričani, da se želite ponovno prijaviti?", "Exchange Rates Data": "Podatki o menjalnih tečajih", "User Custom": "Uporabniške nastavitve po meri", diff --git a/src/locales/ta.json b/src/locales/ta.json index 8d3f9938..d5d88e3a 100644 --- a/src/locales/ta.json +++ b/src/locales/ta.json @@ -2514,11 +2514,14 @@ "Others": "Others", "Cache Expiration Time": "Cache Expiration Time", "Cache Expiration for Map Data": "Cache Expiration for Map Data", - "Disable Map Cache": "Disable Map Cache", + "Cache Expiration for Exchange Rates Data": "Cache Expiration for Exchange Rates Data", + "Disable Cache": "Disable Cache", "Clear All File Cache": "Clear All File Cache", "Are you sure you want to clear all file cache?": "Are you sure you want to clear all file cache?", "Clear Map Data Cache": "Clear Map Data Cache", "Are you sure you want to clear map data cache?": "Are you sure you want to clear map data cache?", + "Clear Exchange Rates Data Cache": "Clear Exchange Rates Data Cache", + "Are you sure you want to clear exchange rates data cache?": "Are you sure you want to clear exchange rates data cache?", "Are you sure you want to re-login?": "மீண்டும் உள்நுழை செய்ய நீங்கள் உறுதியா?", "Exchange Rates Data": "மாற்று விகிதம் தரவு", "User Custom": "தனிப்பயன்", diff --git a/src/locales/th.json b/src/locales/th.json index fa433f76..4c1a5329 100644 --- a/src/locales/th.json +++ b/src/locales/th.json @@ -2514,11 +2514,14 @@ "Others": "Others", "Cache Expiration Time": "Cache Expiration Time", "Cache Expiration for Map Data": "Cache Expiration for Map Data", - "Disable Map Cache": "Disable Map Cache", + "Cache Expiration for Exchange Rates Data": "Cache Expiration for Exchange Rates Data", + "Disable Cache": "Disable Cache", "Clear All File Cache": "Clear All File Cache", "Are you sure you want to clear all file cache?": "Are you sure you want to clear all file cache?", "Clear Map Data Cache": "Clear Map Data Cache", "Are you sure you want to clear map data cache?": "Are you sure you want to clear map data cache?", + "Clear Exchange Rates Data Cache": "Clear Exchange Rates Data Cache", + "Are you sure you want to clear exchange rates data cache?": "Are you sure you want to clear exchange rates data cache?", "Are you sure you want to re-login?": "คุณแน่ใจหรือว่าต้องการเข้าสู่ระบบอีกครั้ง?", "Exchange Rates Data": "ข้อมูลอัตราแลกเปลี่ยน", "User Custom": "กำหนดเองโดยผู้ใช้", diff --git a/src/locales/tr.json b/src/locales/tr.json index f980007f..bc139f08 100644 --- a/src/locales/tr.json +++ b/src/locales/tr.json @@ -2514,11 +2514,14 @@ "Others": "Others", "Cache Expiration Time": "Cache Expiration Time", "Cache Expiration for Map Data": "Cache Expiration for Map Data", - "Disable Map Cache": "Disable Map Cache", + "Cache Expiration for Exchange Rates Data": "Cache Expiration for Exchange Rates Data", + "Disable Cache": "Disable Cache", "Clear All File Cache": "Clear All File Cache", "Are you sure you want to clear all file cache?": "Are you sure you want to clear all file cache?", "Clear Map Data Cache": "Clear Map Data Cache", "Are you sure you want to clear map data cache?": "Are you sure you want to clear map data cache?", + "Clear Exchange Rates Data Cache": "Clear Exchange Rates Data Cache", + "Are you sure you want to clear exchange rates data cache?": "Are you sure you want to clear exchange rates data cache?", "Are you sure you want to re-login?": "Tekrar giriş yapmak istediğinize emin misiniz?", "Exchange Rates Data": "Döviz Kuru Verileri", "User Custom": "Kullanıcı Özel", diff --git a/src/locales/uk.json b/src/locales/uk.json index f6cc7c03..4e6116f3 100644 --- a/src/locales/uk.json +++ b/src/locales/uk.json @@ -2514,11 +2514,14 @@ "Others": "Others", "Cache Expiration Time": "Cache Expiration Time", "Cache Expiration for Map Data": "Cache Expiration for Map Data", - "Disable Map Cache": "Disable Map Cache", + "Cache Expiration for Exchange Rates Data": "Cache Expiration for Exchange Rates Data", + "Disable Cache": "Disable Cache", "Clear All File Cache": "Clear All File Cache", "Are you sure you want to clear all file cache?": "Are you sure you want to clear all file cache?", "Clear Map Data Cache": "Clear Map Data Cache", "Are you sure you want to clear map data cache?": "Are you sure you want to clear map data cache?", + "Clear Exchange Rates Data Cache": "Clear Exchange Rates Data Cache", + "Are you sure you want to clear exchange rates data cache?": "Are you sure you want to clear exchange rates data cache?", "Are you sure you want to re-login?": "Ви впевнені, що хочете увійти знову?", "Exchange Rates Data": "Дані про курси валют", "User Custom": "User Custom", diff --git a/src/locales/vi.json b/src/locales/vi.json index 065b6f37..5130f653 100644 --- a/src/locales/vi.json +++ b/src/locales/vi.json @@ -2514,11 +2514,14 @@ "Others": "Others", "Cache Expiration Time": "Cache Expiration Time", "Cache Expiration for Map Data": "Cache Expiration for Map Data", - "Disable Map Cache": "Disable Map Cache", + "Cache Expiration for Exchange Rates Data": "Cache Expiration for Exchange Rates Data", + "Disable Cache": "Disable Cache", "Clear All File Cache": "Clear All File Cache", "Are you sure you want to clear all file cache?": "Are you sure you want to clear all file cache?", "Clear Map Data Cache": "Clear Map Data Cache", "Are you sure you want to clear map data cache?": "Are you sure you want to clear map data cache?", + "Clear Exchange Rates Data Cache": "Clear Exchange Rates Data Cache", + "Are you sure you want to clear exchange rates data cache?": "Are you sure you want to clear exchange rates data cache?", "Are you sure you want to re-login?": "Bạn có chắc chắn muốn đăng nhập lại không?", "Exchange Rates Data": "Dữ liệu tỷ giá hối đoái", "User Custom": "User Custom", diff --git a/src/locales/zh_Hans.json b/src/locales/zh_Hans.json index 531240e4..a3d1b0a6 100644 --- a/src/locales/zh_Hans.json +++ b/src/locales/zh_Hans.json @@ -2514,11 +2514,14 @@ "Others": "其他", "Cache Expiration Time": "缓存过期时间", "Cache Expiration for Map Data": "地图数据缓存过期时间", - "Disable Map Cache": "禁用地图缓存", + "Cache Expiration for Exchange Rates Data": "汇率数据缓存过期时间", + "Disable Cache": "禁用缓存", "Clear All File Cache": "清除所有文件缓存", "Are you sure you want to clear all file cache?": "您确定要清除所有文件缓存?", "Clear Map Data Cache": "清除地图数据缓存", "Are you sure you want to clear map data cache?": "您确定要清除地图数据缓存?", + "Clear Exchange Rates Data Cache": "清除汇率数据缓存", + "Are you sure you want to clear exchange rates data cache?": "您确定要清除汇率数据缓存?", "Are you sure you want to re-login?": "您确定要重新登录?", "Exchange Rates Data": "汇率数据", "User Custom": "用户自定义", diff --git a/src/locales/zh_Hant.json b/src/locales/zh_Hant.json index e314f82a..b9ceacea 100644 --- a/src/locales/zh_Hant.json +++ b/src/locales/zh_Hant.json @@ -2514,11 +2514,14 @@ "Others": "其他", "Cache Expiration Time": "快取過期時間", "Cache Expiration for Map Data": "地圖資料快取過期時間", - "Disable Map Cache": "停用地圖快取", + "Cache Expiration for Exchange Rates Data": "匯率資料快取過期時間", + "Disable Cache": "停用快取", "Clear All File Cache": "清除所有檔案快取", "Are you sure you want to clear all file cache?": "您確定要清除所有檔案快取?", "Clear Map Data Cache": "清除地圖資料快取", "Are you sure you want to clear map data cache?": "您確定要清除地圖資料快取?", + "Clear Exchange Rates Data Cache": "清除匯率資料快取", + "Are you sure you want to clear exchange rates data cache?": "您確定要清除匯率資料快取?", "Are you sure you want to re-login?": "您確定要重新登入?", "Exchange Rates Data": "匯率資料", "User Custom": "使用者自訂", diff --git a/src/stores/exchangeRates.ts b/src/stores/exchangeRates.ts index 9849ee33..51127449 100644 --- a/src/stores/exchangeRates.ts +++ b/src/stores/exchangeRates.ts @@ -1,6 +1,8 @@ import { ref, computed } from 'vue'; import { defineStore } from 'pinia'; +import { useSettingsStore } from './setting.ts'; + import { type BeforeResolveFunction, itemAndIndex } from '@/core/base.ts'; import type { @@ -47,8 +49,12 @@ function clearExchangeRatesFromLocalStorage(): void { } export const useExchangeRatesStore = defineStore('exchangeRates', () => { + const settingsStore = useSettingsStore(); + const latestExchangeRates = ref(getExchangeRatesFromLocalStorage()); + const exchangeRatesDataCacheEnabled = computed(() => settingsStore.appSettings.exchangeRatesDataCacheExpiration >= 0); + const isUserCustomExchangeRates = computed((): boolean => { if (!latestExchangeRates.value || !latestExchangeRates.value.data) { return false; @@ -99,7 +105,7 @@ export const useExchangeRatesStore = defineStore('exchangeRates', () => { latestExchangeRates.value.data.updateTime = updateTime; - if (changed) { + if (exchangeRatesDataCacheEnabled.value && changed) { setExchangeRatesToLocalStorage(latestExchangeRates.value); } } @@ -120,7 +126,7 @@ export const useExchangeRatesStore = defineStore('exchangeRates', () => { } } - if (changed) { + if (exchangeRatesDataCacheEnabled.value && changed) { setExchangeRatesToLocalStorage(latestExchangeRates.value); } } @@ -135,6 +141,29 @@ export const useExchangeRatesStore = defineStore('exchangeRates', () => { return new Blob([storageData]).size; } + function removeExpiredExchangeRates(removeDataInStore?: boolean): void { + if (settingsStore.appSettings.exchangeRatesDataCacheExpiration > 0) { + const currentExchangeRateData = latestExchangeRates.value; + const now = getCurrentUnixTime(); + + if (currentExchangeRateData && currentExchangeRateData.time) { + if (now - currentExchangeRateData.time >= settingsStore.appSettings.exchangeRatesDataCacheExpiration) { + if (removeDataInStore) { + resetLatestExchangeRates(); + } else { + clearExchangeRatesFromLocalStorage(); + } + } + } + } else if (settingsStore.appSettings.exchangeRatesDataCacheExpiration < 0) { // Disable Cache + if (removeDataInStore) { + resetLatestExchangeRates(); + } else { + clearExchangeRatesFromLocalStorage(); + } + } + } + function resetLatestExchangeRates(): void { latestExchangeRates.value = {}; clearExchangeRatesFromLocalStorage(); @@ -172,11 +201,13 @@ export const useExchangeRatesStore = defineStore('exchangeRates', () => { return; } - latestExchangeRates.value = { - time: now, - data: data.result - }; - setExchangeRatesToLocalStorage(latestExchangeRates.value); + if (exchangeRatesDataCacheEnabled.value) { + latestExchangeRates.value = { + time: now, + data: data.result + }; + setExchangeRatesToLocalStorage(latestExchangeRates.value); + } resolve(data.result); }).catch(error => { @@ -298,6 +329,7 @@ export const useExchangeRatesStore = defineStore('exchangeRates', () => { latestExchangeRateMap, // functions getExchangeRatesCacheSize, + removeExpiredExchangeRates, resetLatestExchangeRates, getLatestExchangeRates, updateUserCustomExchangeRate, diff --git a/src/stores/setting.ts b/src/stores/setting.ts index 6ffe46a6..1bff2859 100644 --- a/src/stores/setting.ts +++ b/src/stores/setting.ts @@ -316,6 +316,11 @@ export const useSettingsStore = defineStore('settings', () => { appSettings.value.mapCacheExpiration = value; } + function setExchangeRatesDataCacheExpiration(value: number): void { + updateApplicationSettingsValue('exchangeRatesDataCacheExpiration', value); + appSettings.value.exchangeRatesDataCacheExpiration = value; + } + // Statistics Settings function setStatisticsDefaultChartDataType(value: number): void { updateApplicationSettingsSubValue('statistics', 'defaultChartDataType', value); @@ -539,6 +544,7 @@ export const useSettingsStore = defineStore('settings', () => { setCurrencySortByInExchangeRatesPage, // -- Browser Cache Settings setMapCacheExpiration, + setExchangeRatesDataCacheExpiration, // -- Statistics Settings setStatisticsDefaultChartDataType, setStatisticsDefaultTimezoneType, diff --git a/src/views/base/settings/AppBrowserCacheSettingPageBase.ts b/src/views/base/settings/AppBrowserCacheSettingPageBase.ts new file mode 100644 index 00000000..cd19c200 --- /dev/null +++ b/src/views/base/settings/AppBrowserCacheSettingPageBase.ts @@ -0,0 +1,112 @@ +import { ref, computed } from 'vue'; + +import { useI18n } from '@/locales/helpers.ts'; + +import { useSettingsStore } from '@/stores/setting.ts'; +import { useExchangeRatesStore } from '@/stores/exchangeRates.ts'; + +import { type NameNumeralValue } from '@/core/base.ts'; +import { type BrowserCacheStatistics } from '@/core/cache.ts'; + +import { + loadBrowserCacheStatistics, + updateMapCacheExpiration, + clearMapDataCache, + clearAllBrowserCaches +} from '@/lib/cache.ts'; + +export function useAppBrowserCacheSettingPageBase() { + const { tt, formatNumberToLocalizedNumerals } = useI18n(); + + const isSupportedFileCache: boolean = 'serviceWorker' in navigator && !!navigator.serviceWorker.controller; + + const settingsStore = useSettingsStore(); + const exchangeRatesStore = useExchangeRatesStore(); + + const loading = ref(true); + const fileCacheStatistics = ref(undefined); + const exchangeRatesCacheSize = ref(undefined); + + const allMapCacheExpirationOptions = computed(() => { + return [ + { name: tt('Disable Cache'), value: -1 }, + { name: tt('format.misc.nDays', { n: formatNumberToLocalizedNumerals(1) }), value: 86400 }, + { name: tt('format.misc.nDays', { n: formatNumberToLocalizedNumerals(7) }), value: 604800 }, + { name: tt('format.misc.nDays', { n: formatNumberToLocalizedNumerals(30) }), value: 2592000 }, + { name: tt('format.misc.nDays', { n: formatNumberToLocalizedNumerals(90) }), value: 7776000 }, + { name: tt('format.misc.nDays', { n: formatNumberToLocalizedNumerals(180) }), value: 15552000 }, + { name: tt('format.misc.nDays', { n: formatNumberToLocalizedNumerals(365) }), value: 31536000 }, + { name: tt('No Expiration'), value: 0 } + ]; + }); + + const allExchangeRatesDataCacheExpirationOptions = computed(() => { + return [ + { name: tt('Disable Cache'), value: -1 }, + { name: tt('format.misc.nDays', { n: formatNumberToLocalizedNumerals(1) }), value: 86400 }, + { name: tt('format.misc.nDays', { n: formatNumberToLocalizedNumerals(7) }), value: 604800 }, + { name: tt('format.misc.nDays', { n: formatNumberToLocalizedNumerals(30) }), value: 2592000 }, + { name: tt('No Expiration'), value: 0 } + ]; + }); + + const mapCacheExpiration = computed({ + get: () => isSupportedFileCache ? settingsStore.appSettings.mapCacheExpiration : -1, + set: (value) => { + settingsStore.setMapCacheExpiration(value); + + if (isSupportedFileCache) { + updateMapCacheExpiration(value); + } + } + }); + + const exchangeRatesDataCacheExpiration = computed({ + get: () => settingsStore.appSettings.exchangeRatesDataCacheExpiration, + set: (value) => { + settingsStore.setExchangeRatesDataCacheExpiration(value); + exchangeRatesStore.removeExpiredExchangeRates(true); + exchangeRatesCacheSize.value = exchangeRatesStore.getExchangeRatesCacheSize(); + } + }); + + function loadCacheStatistics(): Promise { + return new Promise((resolve, reject) => { + loading.value = true; + + loadBrowserCacheStatistics().then(statistics => { + fileCacheStatistics.value = statistics; + exchangeRatesCacheSize.value = exchangeRatesStore.getExchangeRatesCacheSize(); + loading.value = false; + resolve(); + }).catch(error => { + loading.value = false; + reject(error); + }); + }); + } + + function clearExchangeRatesDataCache(): void { + exchangeRatesStore.resetLatestExchangeRates(); + exchangeRatesCacheSize.value = exchangeRatesStore.getExchangeRatesCacheSize(); + } + + return { + // constants + isSupportedFileCache, + // states + loading, + fileCacheStatistics, + exchangeRatesCacheSize, + // computed states + allMapCacheExpirationOptions, + allExchangeRatesDataCacheExpirationOptions, + mapCacheExpiration, + exchangeRatesDataCacheExpiration, + // functions + loadCacheStatistics, + clearMapDataCache, + clearAllBrowserCaches, + clearExchangeRatesDataCache + }; +} diff --git a/src/views/desktop/app/settings/tabs/AppBrowserCacheSettingTab.vue b/src/views/desktop/app/settings/tabs/AppBrowserCacheSettingTab.vue index 464cd519..813a9585 100644 --- a/src/views/desktop/app/settings/tabs/AppBrowserCacheSettingTab.vue +++ b/src/views/desktop/app/settings/tabs/AppBrowserCacheSettingTab.vue @@ -92,6 +92,13 @@ {{ tt('Used storage') }} {{ formatVolumeToLocalizedNumerals(exchangeRatesCacheSize ?? 0, 2) }} + + + + {{ tt('Clear Exchange Rates Data Cache') }} + + @@ -112,6 +119,18 @@ v-model="mapCacheExpiration" /> + + + @@ -155,10 +174,13 @@ const { fileCacheStatistics, exchangeRatesCacheSize, allMapCacheExpirationOptions, + allExchangeRatesDataCacheExpirationOptions, mapCacheExpiration, + exchangeRatesDataCacheExpiration, loadCacheStatistics, clearMapDataCache, - clearAllBrowserCaches + clearAllBrowserCaches, + clearExchangeRatesDataCache } = useAppBrowserCacheSettingPageBase(); const confirmDialog = useTemplateRef('confirmDialog'); @@ -179,5 +201,11 @@ function clearAllFileCache(): void { }); } +function clearExchangeRatesCache(): void { + confirmDialog.value?.open('Are you sure you want to clear exchange rates data cache?').then(() => { + clearExchangeRatesDataCache(); + }); +} + loadCacheStatistics(); diff --git a/src/views/mobile/settings/BrowserCacheSettingPage.vue b/src/views/mobile/settings/BrowserCacheSettingPage.vue index 2b4f8a62..467f885c 100644 --- a/src/views/mobile/settings/BrowserCacheSettingPage.vue +++ b/src/views/mobile/settings/BrowserCacheSettingPage.vue @@ -4,7 +4,7 @@ - + @@ -30,7 +30,8 @@ {{ tt('Cache Expiration Time') }} - + + @@ -75,6 +76,25 @@ v-model="mapCacheExpiration"> + + + + @@ -84,6 +104,10 @@ {{ tt('Clear All File Cache') }} + + {{ tt('Clear Exchange Rates Data Cache') }} + {{ tt('Cancel') }} @@ -112,13 +136,17 @@ const { fileCacheStatistics, exchangeRatesCacheSize, allMapCacheExpirationOptions, + allExchangeRatesDataCacheExpirationOptions, mapCacheExpiration, + exchangeRatesDataCacheExpiration, loadCacheStatistics, clearMapDataCache, - clearAllBrowserCaches + clearAllBrowserCaches, + clearExchangeRatesDataCache } = useAppBrowserCacheSettingPageBase(); const showMapDataCacheExpirationPopup = ref(false); +const showExchangeRatesDataCacheExpirationPopup = ref(false); const showMoreActionSheet = ref(false); function reloadCacheStatistics(done?: () => void): void { @@ -149,5 +177,11 @@ function clearAllFileCache(): void { }); } +function clearExchangeRatesCache(): void { + showConfirm('Are you sure you want to clear exchange rates data cache?', () => { + clearExchangeRatesDataCache(); + }); +} + loadCacheStatistics();