From ebb62f5132706fd13eeed38992e75b8189308ef7 Mon Sep 17 00:00:00 2001 From: imperosol Date: Sun, 17 May 2026 14:30:17 +0200 Subject: [PATCH] use sessionStorage to cache user pictures MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Le sessionStorage est automatiquement vidé à la fermeture de la page, ce qui, dans le cas des photos, est un peu plus fiable et correspond un peu mieux à nos besoins. --- sas/static/bundled/sas/user/pictures-index.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sas/static/bundled/sas/user/pictures-index.ts b/sas/static/bundled/sas/user/pictures-index.ts index de08f858..448a92cd 100644 --- a/sas/static/bundled/sas/user/pictures-index.ts +++ b/sas/static/bundled/sas/user/pictures-index.ts @@ -23,9 +23,9 @@ document.addEventListener("alpine:init", () => { async fetchPictures(): Promise { // Check the cache before hitting the API. - const localStorageKey = "userPictures"; + const storageKey = "userPictures"; const cacheContent: { userId: number; pictures: PictureSchema[] }[] = JSON.parse( - localStorage.getItem(localStorageKey) || "[]", + sessionStorage.getItem(storageKey) || "[]", ); const userPictures = cacheContent.find((obj) => obj.userId === config.userId); if ( @@ -45,12 +45,12 @@ document.addEventListener("alpine:init", () => { cacheContent.push({ userId: config.userId, pictures: pictures }); try { // cache only the pictures of the last 4 visited profiles - localStorage.setItem(localStorageKey, JSON.stringify(cacheContent.slice(-4))); + sessionStorage.setItem(storageKey, JSON.stringify(cacheContent.slice(-4))); } catch { // an exception is raised if the localstorage is entirely filled. // To be as safe as possible, delete the cached pictures. // A cache hit is not worth the page breaking. - localStorage.removeItem(localStorageKey); + sessionStorage.removeItem(storageKey); } return pictures; },