ASP.NET:web.config 在哪里/如何缓存?

编程入门 行业动态 更新时间:2024-10-22 16:45:43
本文介绍了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 在哪里/如何缓存?

本文发布于:2023-11-14 10:09:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1586930.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:缓存   NET   ASP   config   web

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!