HttpContext.Cache和HttpRuntime.Cache中的Cache

来源:互联网 发布:centos minimal full 编辑:程序博客网 时间:2024/04/30 06:52

这是MSDN提供的解释。

HttpContext.Cache:封装有关个别 HTTP 请求的所有 HTTP 特定的信息。

HttpRuntime.Cache:为当前应用程序提供一组 ASP.NET 运行时服务。

使用Reflector去查看其中的源代码

 

HttpContext.Cache:

public Cache Cache{    get    {        return HttpRuntime.Cache;    }}

 

HttpRuntime.Cache:

public static Cache Cache{ get
    {
        if (AspInstallDirectoryInternal == null)
        {
            throw new HttpException(SR.GetString("Aspnet_not_installed", new object[] { VersionInfo.SystemWebVersion }));
        }
        Cache cache = _theRuntime._cachePublic;
        if (cache == null)
        {
            CacheInternal cacheInternal = CacheInternal;
            CacheSection cacheSection = RuntimeConfig.GetAppConfig().Cache;
            cacheInternal.ReadCacheInternalConfig(cacheSection);
            _theRuntime._cachePublic = cacheInternal.CachePublic;
            cache = _theRuntime._cachePublic;
        }
        return cache;
    }
}

结论是两者其实一样。

原创粉丝点击