How to temporarily store summary data with C# .net core

343 Views Asked by At

I am working on an application where upon first loading the user is asked to select a Trust. This selection is then used to filter data from the database in almost every other request. For example, this.context.Companies.Where(c => c.TrustId == trustId); Once a Trust is selected it is very infrequently changed by the user but, a Company which is a part of a Trust may be changed more frequently. The problem I am trying to solve is to find a way to store the Trust's Id so the data is always available until a user selects a new Trust. I am also trying to prevent this data having to come from the front-end with each request. What is the best way to accomplish this?

1

There are 1 best solutions below

0
On BEST ANSWER

If the Trust Id is not sensitive data you can store it inside of the session state. Whenever a request comes in you read the session and get the users trust id.

Session will store data for each user rather than for every user (cache).

You can read more about using and working with session here: https://learn.microsoft.com/en-us/aspnet/core/fundamentals/app-state?view=aspnetcore-3.1