If you are considering thread safety, go with Thread-Local Storage. If thread safety not required, then HttpContext.Current option is useful.
Storing data in Thread Local Storage / HttpContext Current Items
-
04-04-2022 - |
Question
Storing data in Thread-Local Storage or HttpContext.Current.Items
, which one is more efficient….?
This is for storing master data/parameters in a web application.
Code for placing data in both method are:
1. System.Web.HttpContext.Current.Items
public static void Add(string pName, object pValue)
{
System.Web.HttpContext.Current.Items.Add(pName, pValue);
}
2. TLS
public static void Add(string pName, object pValue)
{
Thread.SetData(Thread.GetNamedDataSlot(pName), pValue);
}
Thanks....
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow