ASP.NET:web.config 在哪里/如何缓存? [英] ASP.NET: Where/how is web.config cached?

查看:26
本文介绍了ASP.NET:web.config 在哪里/如何缓存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Microsoft 文档中的某处读到 ASP.NET 的 web.config 的内容已缓存.如果这是真的,缓存在哪里 - 在内存中还是在磁盘上?

I read somewhere in the Microsoft documentation that the content of the ASP.NET's web.config is cached. If that is true, where is it cached - in memory or on disk?

还有一个后续问题:如果我必须集中访问 web.config,是否需要考虑任何性能?

And a follow-up question: are there any performance considerations I have to make, if I have to access the web.config intensively?

推荐答案

它缓存在内存中,缓存在磁盘上没有任何意义,它已经在磁盘上.

Its cached in memory, caching on disk doesn't make any sense, its already on disk.

首先,在 ASP.NET 中,您要确保通过 HttpContext 对象的 GetSection 方法(这使用 ASP.NET 管理的缓存副本)访问配置节.

First of all in ASP.NET you want to ensure you access configuration sections through the HttpContext object's GetSection method (this uses the cached copies managed by ASP.NET).

访问配置值的性能是Section对象(GetSection返回的对象)内部实现的函数.ConfigurationSection 可以简单地充当 DOM 节点的包装器,它可以在每次请求属性时读取该节点.OTH 它可以在内部缓存值并观察变化.

Performance of accessing config values is a function of the internal implementation of the Section object (the object returned by GetSection). A ConfigurationSection may simply act as wrapper for a DOM node which it may read on every request for a property. OTH it could internaly cache the value and watch for changes.

我的建议是让你的代码保持简单,只通过 GetSection 访问你需要的值,而不是试图在别处保存它们的副本,但无论如何都要维护对 GetSection 用于请求的持续时间,如果您要从中获取多个值.

My advice would be keep your code simple and just access the values you need via GetSection rather than attempt to hold copies of them elsewhere but by all means maintain a reference to the object returned by GetSection for the duration of a request if you are going to fetch multiple values from it.

这篇关于ASP.NET:web.config 在哪里/如何缓存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆