Hi @Obakeng Aphane ,
When you call NavigateTo(..., forceLoad: true), you trigger a full browser page load. That tears down the current Blazor runtime, so anything held only in memory—like your IMemoryCache in a WASM (or client-hydrated InteractiveAuto) session—is lost.
Summary:
-
forceLoad: false: SPA navigation, runtime stays alive, in‑memory cache survives. -
forceLoad: true: full reload, new runtime, in‑memory cache emptied.
If you need certain values to survive a hard reload, mirror them into browser storage and rehydrate them on startup.
LocalStorage vs SessionStorage
- localStorage: persists across tabs and browser restarts (until cleared).
- sessionStorage: lasts only for the current tab (ends when tab closes).
- Both store simple string key/value pairs (you JSON‑serialize objects).
- Not secure for sensitive data (visible to the user; no encryption by default).
- Size limits are small (a few MB), so store only what you must.
Minimal pattern:
- Before navigation: serialize the values you care about.
- On app start (e.g., in
OnInitializedAsyncof a root/service): read, deserialize, and repopulate your in‑memory cache.
// Save
await js.InvokeVoidAsync("localStorage.setItem", "myCache", JsonSerializer.Serialize(cacheObject));
// Load
var json = await js.InvokeAsync<string>("localStorage.getItem", "myCache");
if (!string.IsNullOrEmpty(json))
{
var restored = JsonSerializer.Deserialize<MyCacheDto>(json);
// repopulate your cache
}
Doc starting points:
- General Blazor state guidance: State management in Blazor
- Protected (server-side) browser storage: [Protected browser storage](https://free.blessedness.top/en-us/aspnet/core/blazor/state-management/protected-browser-storage?vie…
- Prerender/state transfer (if needed): Prerender and integrate server and client state Keep the in‑memory cache for fast lookups during a single runtime, and only persist the minimal subset you need to survive reloads.
Hope this helps. Let me know if you need any help.