Enterprise Library CacheFactory.GetCacheManager Throws Null Ref

Brian Sullivan picture Brian Sullivan · Aug 12, 2008 · Viewed 8.4k times · Source

I'm trying to convert an application using the 1.1 version of the Enterprise Library Caching block over to the 2.0 version. I think where I'm really having a problem is that the configuration for the different EntLib pieces was split out over several files. Apparently, this used to be handled by the ConfigurationManagerSectionHandler, but is now obsolete in favor of the built-in configuration mechanisms in .NET 2.0.

I'm having a hard time finding a good example of how to do this configuration file splitting, especially in the context of EntLib. Has anyone else dealt with this?

Answer

Brian Sullivan picture Brian Sullivan · Aug 13, 2008

Looks like it was the configuration. I found a good example of the normal, one-file approach here: http://www.devx.com/dotnet/Article/31158/0/page/2

Using an external config file is actually trivial once you figure out the syntax for it. Ex.:

In Web.config:

<cachingConfiguration configSource="cachingconfiguration.config" />

In cachingconfiguration.config:

<?xml version="1.0" encoding="utf-8"?>
<cachingConfiguration defaultCacheManager="Default Cache Manager">
    <backingStores>
        <add name="inMemory" type="Microsoft.Practices.EnterpriseLibrary.Caching.BackingStoreImplementations.NullBackingStore, Microsoft.Practices.EnterpriseLibrary.Caching" />
    </backingStores>
    <cacheManagers>
        <add name="Default Cache Manager" expirationPollFrequencyInSeconds = "60" maximumElementsInCacheBeforeScavenging ="50" numberToRemoveWhenScavenging="10" backingStoreName="inMemory" />
    </cacheManagers>
</cachingConfiguration>

Hopefully this helps somebody!