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:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user