【问题标题】:how to set up cache in a winform c#如何在winform c#中设置缓存
【发布时间】:2013-10-26 22:34:44
【问题描述】:

我找不到关于如何在 winforms c# 中完成简单缓存的体面示例 这就是我想出的,但我得到了例外。

// 这一行已经出现异常 ICacheManager productsCache = CacheFactory.GetCacheManager("MyCacheManager");

例外是: 附加信息:无法加载文件或程序集“Microsoft.Practices.EnterpriseLibrary.Common, Version=5.0.414.0,

我认为我无法正确配置的 app.config 是:

<configuration>
    <configSections>
        <section name="cachingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Caching, Microsoft.Practices.EnterpriseLibrary.Caching, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
    </configSections>
    <cachingConfiguration defaultCacheManager="MyCacheManager">
        <cacheManagers>
            <add name="MyCacheManager" type="Microsoft.Practices.EnterpriseLibrary.Caching, Microsoft.Practices.EnterpriseLibrary.Caching, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                expirationPollFrequencyInSeconds="60" maximumElementsInCacheBeforeScavenging="1000"
                numberToRemoveWhenScavenging="10" backingStoreName="NullBackingStore" />
        </cacheManagers>
        <backingStores>
            <add type="Microsoft.Practices.EnterpriseLibrary.Caching.BackingStoreImplementations.NullBackingStore, Microsoft.Practices.EnterpriseLibrary.Caching, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                name="NullBackingStore" />
        </backingStores>
    </cachingConfiguration>
</configuration>

我使用 entlib 配置来创建 app.config 我不断收到异常。有我可以使用的例子吗? (比 2007 年的示例更新)

10 倍的时间

【问题讨论】:

    标签: c# winforms caching


    【解决方案1】:

    缓存程序集依赖于 Microsoft.Practices.EnterpriseLibrary.Common。您的项目需要引用 Common 程序集以及 Microsoft.Practices.EnterpriseLibrary.Caching。此外,请确保 bin 文件夹中的版本与配置文件中指定的版本相匹配。如果配置是使用使用不同程序集副本的配置工具版本生成的,则可能会导致版本不匹配。

    还可以查看下面的帖子了解其他一些想法:

    http://blogs.msdn.com/b/tomholl/archive/2007/04/19/avoiding-configuration-pitfalls-with-incompatible-copies-of-enterprise-library.aspx

    【讨论】:

    • 两者都被引用。还有什么我可以做的吗?
    • 更新了我上面的答案。
    • 实际上配置文件并没有解决 common.dll 的问题,而另一个文件是caching.dll 在配置文件中被正确提及。所以我还没有弄清楚为什么我不能加载程序集
    猜你喜欢
    • 2014-09-01
    • 1970-01-01
    • 2010-09-16
    • 1970-01-01
    • 2018-02-24
    • 2014-04-12
    • 1970-01-01
    • 2017-03-28
    • 2015-11-16
    相关资源
    最近更新 更多