简体   繁体   中英

how to set up cache in a winform c#

I couldn't find decent examples of how to accomplish simple caching in winforms c# this is what i've come up with but I get exceptions.

// this line already gets an exception ICacheManager productsCache = CacheFactory.GetCacheManager("MyCacheManager");

the exception is: Additional information: Could not load file or assembly 'Microsoft.Practices.EnterpriseLibrary.Common, Version=5.0.414.0,

the app.config which I think I am unable to config properly is:

<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>

I used the entlib config to create the app.config I keep getting exceptions. is there an example I can use? (something more up-to-date than examples from 2007)

10x for your time

The Caching assembly depends on Microsoft.Practices.EnterpriseLibrary.Common. Your project needs to reference the Common assembly as well as Microsoft.Practices.EnterpriseLibrary.Caching. Also, make sure the versions in your bin folder match the version specified in your configuration file. If the config is generated using a version of the configuration tool that uses a different copy of the assemblies, it can create a version mismatch.

Can also check out the post below for some other ideas:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM