PERF: Add more constraint on the Cache Storage usage

PERF: Add more constraint on the Cache Storage usage

Only restricting cache per age wasn’t enough for instances with lots of multimedia usage and high number of posts.

MaxEntries is also more effective on cleanup, and purgeOnQuotaError advertise that Discourse cache can be purged if necessary.

Understanding Storage Quota  |  Workbox  |  Google Developers

diff --git a/app/assets/javascripts/service-worker.js.erb b/app/assets/javascripts/service-worker.js.erb
index cc911ea..ecc8923 100644
--- a/app/assets/javascripts/service-worker.js.erb
+++ b/app/assets/javascripts/service-worker.js.erb
@@ -17,6 +17,8 @@ workbox.routing.registerRoute(
     plugins: [
       new workbox.expiration.Plugin({
         maxAgeSeconds: 7* 24 * 60 * 60, // 7 days
+        maxEntries: 500,
+        purgeOnQuotaError: true, // safe to automatically delete if exceeding the available storage
       }),
     ],
   })

GitHub sha: 1922d4bf

1 Like