refactor: disable service worker caching for API data, transitioning to server-side caching with ServerCacheService to simplify cache management

This commit is contained in:
Julien Froidefond
2025-12-07 11:36:00 +01:00
parent 0bbc92b0e4
commit c4ae6a1b2f
2 changed files with 11 additions and 9 deletions

View File

@@ -77,7 +77,7 @@ size: "1000"; // Récupère TOUS les livres d'un coup
**Objectif : Passer de 3 couches de cache à 1 seule (ServerCacheService)**
- [ ] **2.1 Désactiver le cache SW pour les données API**
- [x] **2.1 Désactiver le cache SW pour les données API**
- Modifier `sw.js` : retirer le cache des routes `/api/komga/*` (sauf images)
- Garder uniquement le cache SW pour : images, static, navigation

View File

@@ -1,5 +1,6 @@
// StripStream Service Worker - Version 1
// Architecture: Cache-as-you-go with Stale-While-Revalidate for data
// Architecture: Cache-as-you-go for images and static resources only
// API data caching is handled by ServerCacheService on the server
const VERSION = "v1";
const STATIC_CACHE = `stripstream-static-${VERSION}`;
@@ -32,10 +33,8 @@ function isNextRSCRequest(request) {
return url.searchParams.has("_rsc") || request.headers.get("RSC") === "1";
}
function shouldCacheApiData(url) {
// Exclude dynamic/auth endpoints that should always be fresh
return !url.includes("/api/auth/session") && !url.includes("/api/preferences");
}
// Removed: shouldCacheApiData - API data is no longer cached by SW
// API data caching is handled by ServerCacheService on the server
// ============================================================================
// Cache Strategies
@@ -215,9 +214,12 @@ self.addEventListener("fetch", (event) => {
return;
}
// Route 3: API data → Stale-While-Revalidate (if cacheable)
if (isApiDataRequest(url.href) && shouldCacheApiData(url.href)) {
event.respondWith(staleWhileRevalidateStrategy(request, DATA_CACHE));
// Route 3: API data → Network only (no SW caching)
// API data caching is handled by ServerCacheService on the server
// This avoids double caching and simplifies cache invalidation
if (isApiDataRequest(url.href)) {
// Let the request pass through to the network
// ServerCacheService will handle caching server-side
return;
}