-1

We're using Blazor (Server Side) and .NET 5 for a new solution which requires use of session to eliminate round trips to the DB for the exact same data.

We're currently using the recommended ProtectedBrowserStorage model but we ran into the 25MB limitation of the browser when we tried to store a relatively large dataset. So this may not be ideal when we're dealing with many 1000's of records that need to be viewed and manipulated by the end user. We're trying to optimize performance for end users. This is a connected Desktop scenario.

Is there a better way to handle large session variables in Blazor that isn't limited by the client browser?

Thanks in advance.

Alex A
  • 59
  • 10

4 Answers4

1

to eliminate round trips to the DB for the exact same data.

You could use Caching. That allows sharing data between Sessions/Users (could be a risk, just be careful). It will also reduce I/O.

Caching is server-side and that's where your app runs too. So it wil be generally faster. But it's not clear what your memory constraints (per user) are.

H H
  • 263,252
  • 30
  • 330
  • 514
1

You can use IndexedDb that is supported in all major browsers.

I use this object store db in a PWA but you can use it with a Blazor Server side app or a Blazor WASM client app.

The limit of an IndexedDB aren't a problem for your and for mostly any situation.
The browser manages the data and you only need to decide your policy on how to refresh them.

Start from this library https://github.com/amuste/DnetIndexedDb and try some samples.

Nicola Biada
  • 2,325
  • 1
  • 8
  • 22
0

There are a few different ways you can do this depending on your needs:

Cascading Parameters: A good video for the basics of it - https://www.youtube.com/watch?v=ZmDMKp1Q8kA

An AppState approach: A good video for it covering two different ways: https://www.youtube.com/watch?v=BB4lK2kfKf0

The main issue with both of these is they are still by session and will be gone on refresh or a new tab.

The only other solution I know of is by using redis, this would keep the data as long as you want to keep it for but it would not be in blazor. Good video of it: https://www.youtube.com/watch?v=UrQWii_kfIE

Kyle Cintron
  • 316
  • 2
  • 6
  • Okay. We're running with IIS, Blazor, and MSSQL as the backend (enterprise set up). I used to just use the server SessionState with WebForms and MVC, but that apparently won't work with Blazor. We're also tuning the DB so queries across 70m records won't lag... – Alex A Aug 25 '21 at 19:10
  • You can also check out the two answers on my own question I asked a little while back that's similar to your own: [link](https://stackoverflow.com/questions/67938642/blazor-server-how-to-persist-data-across-multiple-tabs-and-refreshes) – Kyle Cintron Aug 25 '21 at 19:14
0

It depends on how many concurrent users you have, and your system resources.

A singleton service persists across sessions, and you can use whatever data structures you want.

Bennyboy1973
  • 3,413
  • 2
  • 11
  • 16