views:

97

answers:

1

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?

+1  A: 

Hi, 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.

Doesn't show how to programmatically do things, but answer my underlying need so I'm accepting :)
urig