refactor: disable service worker caching for API data, transitioning to server-side caching with ServerCacheService to simplify cache management
This commit is contained in:
@@ -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)**
|
**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)
|
- Modifier `sw.js` : retirer le cache des routes `/api/komga/*` (sauf images)
|
||||||
- Garder uniquement le cache SW pour : images, static, navigation
|
- Garder uniquement le cache SW pour : images, static, navigation
|
||||||
|
|||||||
18
public/sw.js
18
public/sw.js
@@ -1,5 +1,6 @@
|
|||||||
// StripStream Service Worker - Version 1
|
// 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 VERSION = "v1";
|
||||||
const STATIC_CACHE = `stripstream-static-${VERSION}`;
|
const STATIC_CACHE = `stripstream-static-${VERSION}`;
|
||||||
@@ -32,10 +33,8 @@ function isNextRSCRequest(request) {
|
|||||||
return url.searchParams.has("_rsc") || request.headers.get("RSC") === "1";
|
return url.searchParams.has("_rsc") || request.headers.get("RSC") === "1";
|
||||||
}
|
}
|
||||||
|
|
||||||
function shouldCacheApiData(url) {
|
// Removed: shouldCacheApiData - API data is no longer cached by SW
|
||||||
// Exclude dynamic/auth endpoints that should always be fresh
|
// API data caching is handled by ServerCacheService on the server
|
||||||
return !url.includes("/api/auth/session") && !url.includes("/api/preferences");
|
|
||||||
}
|
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// Cache Strategies
|
// Cache Strategies
|
||||||
@@ -215,9 +214,12 @@ self.addEventListener("fetch", (event) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Route 3: API data → Stale-While-Revalidate (if cacheable)
|
// Route 3: API data → Network only (no SW caching)
|
||||||
if (isApiDataRequest(url.href) && shouldCacheApiData(url.href)) {
|
// API data caching is handled by ServerCacheService on the server
|
||||||
event.respondWith(staleWhileRevalidateStrategy(request, DATA_CACHE));
|
// 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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user