feat: implement caching for Frankfurter API exchange rates

- Added a caching strategy for the Frankfurter API using Service Worker with StaleWhileRevalidate.
- Removed the local storage caching logic from the currency tool to streamline data fetching.
- Updated the currency tool to rely on the Service Worker for managing exchange rate data.
This commit is contained in:
typist
2025-10-30 09:49:30 +08:00
parent e88770dd3f
commit 1bcbd3e37d
2 changed files with 22 additions and 63 deletions

View File

@@ -54,6 +54,21 @@ export default defineConfig(({ mode }) => ({
}
}
},
{
// Frankfurter API 汇率缓存
urlPattern: /^https:\/\/api\.frankfurter\.app\/.*/i,
handler: 'StaleWhileRevalidate',
options: {
cacheName: 'currency-rates-cache',
expiration: {
maxEntries: 5,
maxAgeSeconds: 60 * 60 * 12 // 12 小时
},
cacheableResponse: {
statuses: [0, 200]
}
}
},
{
// Google Fonts 样式表缓存
urlPattern: /^https:\/\/fonts\.googleapis\.com\/.*/i,