question

biprism avatar image
0 Votes"
biprism asked Bruce-SqlWork answered

what is the recommeded caching strategy in Blazor Server App?

We have quite a good amount of referenced data that we need to use throughout our Blazor Server application. Also the application will be used on all devices - phones, tablets, and laptops.
What would be the best approach to cache those data, if possible.?
Does Blazor provide any caching strategy?

dotnet-aspnet-core-blazor
· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @biprism ,

Could you please tell me which reference data you want to use in your blazor? Does these reference data is other webstie page or else?

0 Votes 0 ·
biprism avatar image biprism BrandoZhang-MSFT ·

well, no it is not from other web site or page.
For example, GenderCode - M for Male, F for Female, when I get the data - the " Member" data from my database I get only F or M, but when I display on page I should display as Male or Female.
I also have a database table table (let's say it is "CodeDescription" that defines the reference code so I get that too to see what is M and what is F. I do not want to get this CodeDescription table every time I get the Gender Code from Member table.
I wanted to cache this code description data so that I can get the description from the cache rather than getting it from database every time.
Most of these reference data are very static meaning they do not change very often or do not change at all.

0 Votes 0 ·

In my opinion, this should be registered as an Singleton service, then you could read it when the project started if these things is not changed. Then you could directly using these things inside the Blazor application. This means it used the memory to store the value.

0 Votes 0 ·

1 Answer

Bruce-SqlWork avatar image
0 Votes"
Bruce-SqlWork answered

you should remember that blazor server is already memory heavy as it needs to keep state for every connection. You can use the asp.net cache

https://docs.microsoft.com/en-us/aspnet/core/performance/caching/memory?view=aspnetcore-6.0&viewFallbackFrom=aspnetcore-2.2



5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.