以编程方式配置 EntLib CAB CacheManager

发布于 2024-08-03 08:32:58 字数 113 浏览 6 评论 0原文

目前,我必须在 app.config 中包含大量 XML 才能使 CAB CacheManager 运行,而且我宁愿将配置隐藏在代码中。

有没有办法以编程方式配置企业库缓存应用程序块的缓存管理器?

Currently I'm having to include a significant chunk of XML in the app.config to get the CAB CacheManager going and I'd rather hide the configuration away in my code.

Is there any way to programmatically configure an Enterprise Library Caching Application Block's CacheManager?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

日裸衫吸 2024-08-10 08:32:58

为什么不在 web.config 中使用 configSource 属性将 CAB 配置移至另一个配置文件?

例如:

<?xml version="1.0"?>
<configuration>
    <configSections>
        <section name="cachingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Caching.Configuration.CacheManagerSettings, Microsoft.Practices.EnterpriseLibrary.Caching, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
         ....


</configSections>

 <cachingConfiguration configSource="Config\Caching.config" />

然后,在 Config\Caching.config 中:

<?xml version="1.0" encoding="utf-8" ?>
<cachingConfiguration defaultCacheManager="DefaultCacheManager">
    <cacheManagers>
        <add name="DefaultCacheManager"
             expirationPollFrequencyInSeconds="60"
             maximumElementsInCacheBeforeScavenging="1000"
             numberToRemoveWhenScavenging="10"
             backingStoreName="Null Storage"
             type="Microsoft.Practices.EnterpriseLibrary.Caching.CacheManager, Microsoft.Practices.EnterpriseLibrary.Caching, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>

..

据我所知,您可以为 web.config 中的每个 configSection 使用单独的配置文件

why don't you use configSource attribute in your web.config to move to another config file the CAB configuration?

For Example:

<?xml version="1.0"?>
<configuration>
    <configSections>
        <section name="cachingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Caching.Configuration.CacheManagerSettings, Microsoft.Practices.EnterpriseLibrary.Caching, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
         ....


</configSections>

 <cachingConfiguration configSource="Config\Caching.config" />

And then, in Config\Caching.config:

<?xml version="1.0" encoding="utf-8" ?>
<cachingConfiguration defaultCacheManager="DefaultCacheManager">
    <cacheManagers>
        <add name="DefaultCacheManager"
             expirationPollFrequencyInSeconds="60"
             maximumElementsInCacheBeforeScavenging="1000"
             numberToRemoveWhenScavenging="10"
             backingStoreName="Null Storage"
             type="Microsoft.Practices.EnterpriseLibrary.Caching.CacheManager, Microsoft.Practices.EnterpriseLibrary.Caching, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>

..

As far as I know, you can use a separate config file for each configSection in your web.config

s.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文