0

Currently I am using 'Session' to keep the datatables in memory. But after doing few R&Ds, I came to know the it is not a good practice e.g.

Session("Syllabus") = RegistartionLogic.GetSyllabusInfo(Session("StudentID"))

Requirement:

  • The items of dropdown will be different based on student-type.
  • The dropdown data will be fetched from DB and these controls are used in more than one screen.
  • Multiple DB call is not preferred from different screens for same
    data.
  • So I need to call only one DB call, keep the data in memory and
    then read data from memory next time onward.

I tried with 'cache' as well, but the issue was "Cache is not unique to the user.The scope of the data caching is within the application domain unlike "session". Every user can able to access this objects".

Kindly help me out.

Pranav Kumar
  • 249
  • 1
  • 5
  • 16

1 Answers1

1

For your scenario, HttpContext.Current.Cache should work. Yes cache is not unique to the user. But cache key can be made unique.

var studentId = GetStudentIdFromRequest();
var cacheKey = "SyllabusInfoCacheKey_" + studentId;

Then you can make use of the unique cachekey, to insert and later get values for the particular student.
Session is also at Application level. Every user has a ASP.NET_SessionId cookie that is sent from client side and used at the server side to store/retrieve values.
Note: For Session and Asp.Net Cache to work in a load balanced environment, load balancer should be sticky.

Boney
  • 2,072
  • 3
  • 18
  • 23