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....

Was it helpful?

Solution

If you are considering thread safety, go with Thread-Local Storage. If thread safety not required, then HttpContext.Current option is useful.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top