From a09f1ea1a31b2786373d84d69b0ce3dfb0509cc2 Mon Sep 17 00:00:00 2001 From: Lim Chee Aun Date: Mon, 2 Jan 2023 14:23:00 +0800 Subject: [PATCH] SWR cache /statuses/:id/context --- public/sw.js | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/public/sw.js b/public/sw.js index 814b3820..8bf163f7 100644 --- a/public/sw.js +++ b/public/sw.js @@ -46,20 +46,20 @@ const apiExtendedRoute = new RegExpRoute( ); registerRoute(apiExtendedRoute); -// Not caching API requests, doesn't seem to be necessary fo now -// -// const apiRoute = new RegExpRoute( -// /^https?:\/\/[^\/]+\/api\//, -// new StaleWhileRevalidate({ -// cacheName: 'api', -// plugins: [ -// new ExpirationPlugin({ -// maxAgeSeconds: 60, // 1 minute -// }), -// new CacheableResponsePlugin({ -// statuses: [0, 200], -// }), -// ], -// }), -// ); -// registerRoute(apiRoute); +const apiRoute = new RegExpRoute( + // Matches: + // - statuses/:id/context - some contexts are really huge + /^https?:\/\/[^\/]+\/api\/v\d+\/(statuses\/\d+\/context)/, + new StaleWhileRevalidate({ + cacheName: 'api', + plugins: [ + new ExpirationPlugin({ + maxAgeSeconds: 5 * 60, // 5 minutes + }), + new CacheableResponsePlugin({ + statuses: [0, 200], + }), + ], + }), +); +registerRoute(apiRoute);