【问题标题】:Storing data in Thread Local Storage / HttpContext Current Items将数据存储在 Thread Local Storage / HttpContext Current Items
【发布时间】:2013-04-19 05:38:49
【问题描述】:

将数据存储在 Thread-Local Storage 或 HttpContext.Current.Items 中,哪个更高效......?
这是用于在 Web 应用程序中存储主数据/参数。
在这两种方法中放置数据的代码是:

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);
}


谢谢....

【问题讨论】:

    标签: c# asp.net httprequest thread-local-storage


    【解决方案1】:

    如果您正在考虑线程安全,请使用线程本地存储。如果不需要线程安全,那么 HttpContext.Current 选项很有用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-02-06
      • 2015-03-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-12
      相关资源
      最近更新 更多