With the reference to the structure of session module in ASP.NET below:
As I understand, when the application uses distributed session provider (.e.g. Redis in Azure), the SessionStateModule will deserializes the user's session data into Session dictionary at the beginning of a request.
What I'm wondering is whether the module will deserialize everything in user's session, or just session entry that accessed during that request? Let's say user's session has 3 entries A, B, C and only entry B is read in current request, will the module retrieve all 3 entries from distributed session, deserialize them into Session dictionary?
If it deserializes everything, the more data in user's session, the slower each request will become? since the more data will need to be retrieved/deserialized
Best How To :
Yes, session state assumes that provider deserializes/serializes whole state and hence more data is stored more time it takes to start/end request.
As an option if you need to store a lot of data - store infrequently needed pieces outside of session state and keep information on location of the data in the session state. Note that you'd need to figure security and expiration implications of such split state storage.
Alternatively if you are implementing your own provider you can implement your own
SessionStateStoreData class with
Item method that will dynamically query items as needed. Unfortunately there is no
async version of the class and hence remote calls to get data will lead to unexpected delays in request processing code along with blocking threads from processing request.
More details can be found starting from Implementing a Session-State Store Provider