From eae78fbe5b6c0eec1ae26a84d2974f5b18d1895b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timoth=C3=A9e=20Poussard?= <tpoussard@neogeo.fr>
Date: Wed, 9 Mar 2022 10:27:04 +0100
Subject: [PATCH] add mapcache route and all osm tile & allow filter out 204
 status for api cache

---
 src/service-worker.js | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/src/service-worker.js b/src/service-worker.js
index 1b04819c..7dd25fb9 100644
--- a/src/service-worker.js
+++ b/src/service-worker.js
@@ -29,10 +29,15 @@ if (workbox) {
     new RegExp('.*/api/.*'),
     new workbox.strategies.NetworkFirst({
       cacheName: 'api',
+      plugins: [
+        new workbox.cacheableResponse.Plugin({
+          statuses: [0, 200],
+        }),
+      ],
     })
   );
   workbox.routing.registerRoute(
-    /^https:\/\/c\.tile\.openstreetmap\.fr/,
+    /^https:\/\/[a-zA-Z]\.tile\.openstreetmap\.fr/,
     new workbox.strategies.CacheFirst({
       cacheName: 'osm',
       plugins: [
@@ -46,6 +51,21 @@ if (workbox) {
       ],
     })
   );
+  workbox.routing.registerRoute(
+    /^https:\/\/osm\.geo2france\.fr\/mapcache/,
+    new workbox.strategies.CacheFirst({
+      cacheName: 'mapcache',
+      plugins: [
+        new workbox.cacheableResponse.Plugin({
+          statuses: [0, 200],
+        }),
+        new workbox.expiration.Plugin({
+          maxAgeSeconds: 60 * 60 * 24 * 365,
+          // maxEntries: 30, pour limiter le nombre d'entrée dans le cache
+        }),
+      ],
+    })
+  );
 
 }
 
-- 
GitLab