System.Web.HttpContext.Current.Cache与System.Web.HttpRuntime.Cache指向同一个引用

来源:互联网 发布:c语言是否窗口 编辑:程序博客网 时间:2024/06/07 05:34

System.Web.HttpContext.Current.Cache查看源码后,这里的Cache对象引用的是System.Web.HttpRuntime.Cache的静态变量

        /// <devdoc>        ///    <para>        ///       Gets a reference to the System.Web.Cache.Cache object for the current request.        ///    </para>        /// </devdoc>        public Cache Cache {            get { return HttpRuntime.Cache;}        }

源码地址:https://referencesource.microsoft.com/#System.Web/HttpContext.cs

虽然两者指向了同一个引用,但是HttpContext.Current.Cache很明显只适用Web当前上下文,HttpContext.Current变量及HttpContext对象只适用Web上下文

        /// <devdoc>        ///    <para>Returns the current HttpContext object.</para>        /// </devdoc>        public static HttpContext Current {            get {#if DBG                if (NeedDebugAssertOnAccessToCurrent) {                    Debug.Assert(ContextBase.Current != null);                }#endif                return ContextBase.Current as HttpContext;            }             set {                ContextBase.Current = value;            }        }



0 0